I'm in the process of setting up an Apache web server on an Ubuntu VM using Django with the intention of configuring it for production. I used this walk-through to get Apache and Django up and running, and since, I've been following along with the official tutorial provided in the Django docs. I've gotten up to Part 6, which discusses managing static files, but I can't seem to get the styling to apply.
Abbreviated Server File Structure:
/etc/
--apache2/
----apache2.conf
....
/build/
--django/ <-- Django installation
--tstdj/ <-- target project
----manage.py
----polls/
------...
------static/
--------polls
----------styles.css
------templates/
----------....
----------index.html
------urls.py
------views.py
----static/
------....
------polls/
--------styles.css
----tstdj/
------....
------settings.py
------urls.py
------wsgi.py
/etc/apache2/apache2.conf:
....
WSGIDaemonProcess www-data processes=2 threads=12 python-path=/build/tstdj
WSGIProcessGroup www-data
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIScriptAlias / /build/tstdj/tstdj/wsgi.py
Alias /static/ /build/tstdj/static
<Directory /build/tstdj/tstdj>
Require all granted
</Directory>
<Directory /build/tstdj/static>
Require all granted
</Directory>
<Directory /static>
Require all granted
</Directory>
/build/tstdj/tstdj/settings.py:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
....
STATIC_ROOT = BASE_DIR + '/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = [
'/build/tstdj/polls/static',
]
#STATIC_DIRS = 'static'
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
/build/tstdj/polls/templates/polls/index.html:
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'polls/styles.css' %}">
<p><span>My name Jeff</span></p>
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="{% url 'polls:detail' question.id %}">{{ question. question_text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
/build/tstdj/polls/static/polls/styles.css:
li a {
color: green;
}
Obviously, the desired output in this case is to have green links. The network tab of the inspector shows 403 errors on the styles.css file, as does attempting to go straight to localhost:8080/static/
.
I've run python manage.py collectstatic
and sudo service apache2 restart
Lord knows how many times. I know there are means of getting the styling to work in development, but I've yet to get them functional for production.