[英]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.