[英]Django Static files not found
I am working on a website which uses Django framework. 我正在使用Django框架的网站上工作。 I have put my project related static files in the folder called
our_static
and collectstatic
files in static
. 我已将项目相关的静态文件放在名为
our_static
的文件夹中,并将collectstatic
文件放在static
。 Below are my settings 以下是我的设置
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "our_static"),
]
base.html file: 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>
Here our_static
files are not at all getting read. 这里的
our_static
文件根本没有被读取。 My style.css
is in our_static
folder. 我的
style.css
位于our_static
文件夹中。
EDIT: I am using AWS EC2 ubuntu 14.04 as my server, the website is working fine in localhost but not in AWS ubuntu server. 编辑:我使用AWS EC2 ubuntu 14.04作为我的服务器,该网站在localhost中工作正常但在AWS ubuntu服务器中没有。 I am using the Apache2 server.
我正在使用Apache2服务器。
More config: 更多配置:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATICFILES_FINDERS =[
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
my Apache2 config: 我的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
Your issue is in your Apache configuration - probably in your httpd.conf
file. 您的问题出在您的Apache配置中 - 可能在您的
httpd.conf
文件中。 Take a look at any tutorial like https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-centos-7#configure-apache which will explain how to set this up. 看看任何教程,如https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-centos-7#configure-apache解释如何设置它。 An example
httpd.conf
file would look like the following if you're using mod_wsgi
: 如果您使用
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
You should also inspect the output of your Apache error logs, which will help debug. 您还应该检查Apache错误日志的输出,这将有助于调试。 They're usually at
/var/log/apache2/error.log
它们通常位于
/var/log/apache2/error.log
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.