0

I'm currently trying to learn Django, however, I can't get Apache to serve the static files. I've tried using the development server or gunicorn both running on port 8000.

I can access the page just fine, but Bootstrap is not loaded. Also, when I'm trying to open the static files directly (mydomain.com:8000/static/app/css/bootstrap.min.css) I get a "Connection Refused".

<VirtualHost *:8000>
DocumentRoot /home/django/project/
ServerName mydomain.com
Alias /static /home/django/project/static

<Directory /home/django/project/static>
    Require all granted
</Directory>

root@ip-:~# tree -dc /home/django/project/
/home/django/project/
|-- app
|   |-- templates
|   |   `-- app
|   |       `-- includes
|   |-- __pycache__
|   |-- static
|   |   `-- app
|   |       `-- bootstrap-3.3.6-dist
|   |           |-- css
|   |           |-- fonts
|   |           `-- js
|   `-- migrations
|       `-- __pycache__
|-- static
|   |-- admin
|   |   |-- css
|   |   |-- fonts
|   |   |-- img
|   |   |   `-- gis
|   |   `-- js
|   |       |-- admin
|   |       `-- vendor
|   |           |-- jquery
|   |           `-- xregexp
|   |-- bootstrap-3.3.6-dist
|   |   |-- css
|   |   |-- fonts
|   |   `-- js
|   `-- app
|       |-- bootstrap-3.3.6-dist
|       |   |-- css
|       |   |-- fonts
|       |   `-- js
|       |-- css
|       |-- fonts
|       `-- js
`-- project
    `-- __pycache__

From settings.py:

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = (os.path.join(os.path.dirname(__file__),'static'),)
theCed7
  • 125
  • 3
  • 15
  • Have you specified the STATIC_ROOT and STATIC_DIRS in your settings.py? – Ankush Raghuvanshi Jul 19 '16 at 11:18
  • Possible duplicate of [Django 1.7 - Serving static files](http://stackoverflow.com/questions/26580700/django-1-7-serving-static-files) – Anuj Jul 19 '16 at 11:31
  • Is the bootstrap.min.css in static/app/css ? – ger.s.brett Jul 19 '16 at 11:57
  • @ger.s.brett Yes, it most certainly is. I used `tree -d` for better legibility. – theCed7 Jul 19 '16 at 12:31
  • @AnkushRaghuvanshi Yes I have: `STATIC_ROOT = os.path.join(BASE_DIR, "static/")` and `STATICFILES_DIRS = (os.path.join(os.path.dirname(__file__),'static'),)` – theCed7 Jul 19 '16 at 12:42
  • Shouldn't I be able to access the static files without any instance of django running by opening up `http://ydomain.com:8000/static/medisearch/css/bootstrap.min.css`? Is there an issue with my Apache config? – theCed7 Jul 19 '16 at 12:46
  • Silly question but what do your filesystem permissions look like on /home/django/project/? Is it possible Apache can't read them in the first place? Apache runs as its own user, it looks like you have a separate "django" user as well. – Ivan Jul 19 '16 at 15:09

0 Answers0