I am working on a website which uses Django framework. I have put my project related static files in the folder called our_static
and collectstatic
files in 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:
{% 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. My style.css
is in our_static
folder.
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. I am using the Apache2 server.
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:
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. 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. An example httpd.conf
file would look like the following if you're using mod_wsgi
:
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. They're usually at /var/log/apache2/error.log
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.