簡體   English   中英

如何在 wsgi django 項目中包含靜態文件?

[英]How to include staticfiles in wsgi django project?

今天我在將 static 個文件連接到我的項目時遇到了問題。

如果我使用命令運行 django 應用程序: python manage.py runserver <ip>:<port>然后找到 static 個文件。 如果我將 django 應用程序作為 wsgi 服務 ( systemctl start myapp ) 運行,我會收到一條錯誤消息,指出未找到 static 文件。

我在 /home/alevt/health_check 中的項目。 我有下一個項目結構:

---- client
-------- manage.py
-------- my.ini
-------- app
------------ urls.py
------------ settings.py
------------ wsgi.py
-------- health_app
------------ urls.py
------------ static
--------------- scripts
----------------- myscript.js
------------ templates
--------------- index.html

設置.py

INSTALLED_APPS = [ ...
'django.contrib.staticfiles',
'health_app',
...]
 
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

index.html

{% load static %}
<script src="{% static 'scripts/myscript.js' %}"></script>

錯誤

Not Found: /static/scripts/myscript.js

我的配置文件

[uwsgi]
http = 10.107.14.161:8000
module=app.wsgi:application
chdir = /home/alevt/health_check/client/
wsgi-file = /home/alevt/health_check/client/app/wsgi.py
virtualenv=/home/alevt/health_check/env
single-interpreter = true
enable-threads = true
master = true

還有我的服務檔案

Description=uWSGI instance to serve myproject
 
[Service]
ExecStart=/usr/bin/bash -c 'uwsgi --ini /home/alevt/health_check/client/my.ini'
KillSignal=SIGQUIT
Type=notify
 
[Install]
WantedBy=multi-user.target```

嘗試這個:

 STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'health_app/static/')
)

我的.ini文件:

static = /health_app/static

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM