-2

I am beginner in Django. When i hosted a django application with mod_wsgi in Apache2.4. I got a 404 error for my base.css. Any help should be appreciated.

<IfModule mod_alias.c>
Alias /cgi-bin /home/vetconnect/public_html/cgi-bin` 
Alias /static/ /home/vetconnect/djangosites/vetconnect/static/ 
</IfModule> 
<IfModule mod_wsgi.c> 
WSGIScriptAlias / /home/vetconnect/djangosites/vetconnect.wsgi 
WSGIDaemonProcess vetconnect processes=7 threads=1 display-name=%{GROUP} 
WSGIProcessGroup vetconnect WSGIApplicationGroup %{GLOBAL} 
</IfModule>
Zagorodniy Olexiy
  • 2,132
  • 3
  • 22
  • 47
nidhin
  • 359
  • 1
  • 3
  • 13
  • Give us more information, how you configure apache server for static files – Zagorodniy Olexiy Dec 14 '16 at 13:14
  • Alias /cgi-bin /home/vetconnect/public_html/cgi-bin #Alias /static/ /home/vetconnect/virtualenv3.5/lib/python3.5/site-packages/django/contrib/admin/static/ Alias /static/ /home/vetconnect/djangosites/vetconnect/static/ `WSGIScriptAlias / /home/vetconnect/djangosites/vetconnect.wsgi WSGIDaemonProcess vetconnect processes=7 threads=1 display-name=%{GROUP} WSGIProcessGroup vetconnect WSGIApplicationGroup %{GLOBAL} ` – nidhin Dec 14 '16 at 13:26
  • It is hard to read this. Add it in to your question – Zagorodniy Olexiy Dec 14 '16 at 13:27
  • ` `Alias /cgi-bin /home/vetconnect/public_html/cgi-bin` `Alias /static/ /home/vetconnect/djangosites/vetconnect/static/` `` `` `WSGIScriptAlias / /home/vetconnect/djangosites/vetconnect.wsgi` `WSGIDaemonProcess vetconnect processes=7 threads=1 display-name=%{GROUP}` `WSGIProcessGroup vetconnect` `WSGIApplicationGroup %{GLOBAL}` `` – nidhin Dec 14 '16 at 13:32
  • Alias /static/ /home/vetconnect/djangosites/vetconnect/static/ I configured the css in this directory. But in browser i got 404 error. – nidhin Dec 14 '16 at 13:33
  • Are you running ``python manage.py collectstatic`` after having configured Django to tell it where to put the static files by setting ``STATIC_ROOT``? – Graham Dumpleton Dec 14 '16 at 20:31

1 Answers1

0

According official django documentation to manage static files you have check this points:

django.contrib.staticfiles is included in your INSTALLED_APPS.

define STATIC_URL in settings.py, for example STATIC_URL = '/static/'

Use {% load static %} in templates.

you can define a list of directories STATICFILES_DIRS

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    '/var/www/static/',
]

Finally, you need to set the script alias so that Apache will pass requests for the root domain to the wsgi.py file and server static and media files. Here is the link how to do this with full description

<VirtualHost *:80>
    . . .

    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

</VirtualHost>
Zagorodniy Olexiy
  • 2,132
  • 3
  • 22
  • 47