[英]Django Static files not found
我正在使用Django框架的網站上工作。 我已將項目相關的靜態文件放在名為our_static
的文件夾中,並將collectstatic
文件放在static
。 以下是我的設置
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "our_static"),
]
base.html文件:
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{% static 'style.css' %}" />
</head>
這里的our_static
文件根本沒有被讀取。 我的style.css
位於our_static
文件夾中。
編輯:我使用AWS EC2 ubuntu 14.04作為我的服務器,該網站在localhost中工作正常但在AWS ubuntu服務器中沒有。 我正在使用Apache2服務器。
更多配置:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATICFILES_FINDERS =[
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
我的Apache2配置:
Alias /static /home/ubuntu/pythonserver/static
<Directory /home/ubuntu/pythonserver/static>
Require all granted
</Directory>
<Directory /home/ubuntu/pythonserver/pythonserver>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess pythonserver python-path=/home/ubuntu/pythonserver python-home=/home/ubuntu/knowmenow/
WSGIProcessGroup pythonserver
WSGIScriptAlias / /home/ubuntu/pythonserver/pythonserver/wsgi.py
您的問題出在您的Apache配置中 - 可能在您的httpd.conf
文件中。 看看任何教程,如https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-centos-7#configure-apache解釋如何設置它。 如果您使用mod_wsgi
示例httpd.conf
文件將如下所示:
Alias /static /home/user/myproject/static
<Directory /home/user/myproject/static>
Require all granted
</Directory>
<Directory /home/user/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-path=/home/user/myproject:/home/user/myproject/myprojectenv/lib/python2.7/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /home/user/myproject/myproject/wsgi.py
您還應該檢查Apache錯誤日志的輸出,這將有助於調試。 它們通常位於/var/log/apache2/error.log
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.