I am using Django 1.8, python 3.4.3 and Apache 2.4.7, I have tried a lot of configurations and I can't see what I'm doing wrong. When I was using debug mode everything but the images was running perfect, and I solved the images issue by using this on urls.py:
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
Later I turned DEBUG=False
and the Images stopped working, thats why started to read about serving Static and Media files on Apache. And with the basic configurations everything seemed to be working right, but the images stopped working again, and after trying some configurations My App CSS and JS just stopped working, so I used collectstatic
and after that, also the Admin lost its CSS and Js, but when I turn it True
again, CSS and JS starts working again on both, App and Admin.
Now on DEBUG=False nothing is working, admin Static, my app Static files, and media files, nothing.
These are my settings:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))
MEDIA_ROOT = PROJECT_ROOT + '/archivos/'
MEDIA_URL = '/archivos/' #put whatever you want that when url is rendered it will be /archivos/imagename.jpg
DEBUG = True #False
ALLOWED_HOSTS = ['localhost','127.0.0.1']
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
This is my /etc/apache2/sites-enabled/000-default.conf
file:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName django.myproject
Alias /static /home/developer/myproject/static
<Directory /home/developer/myproject/static>
Require all granted
</Directory>
Alias /archivos/ /home/developer/myproject/archivos/
<Directory /home/developer/myproject/archivos>
Require all granted
</Directory>
<Directory /home/developer/myproject/myapp>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-path=/home/developer/myproject:/home/developer/myproject/projectvenv/lib/python3.4/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /home/developer/myproject/projectsystem/wsgi.py
</VirtualHost>
If I turn Debug=True, CSS and JS of Admin and App starts working again, only the images (media files) don't.