python - Serving static files on Apache with Django (404 error) -


i've been trying setup apache (2.2.15) proxy gunicorn , django (1.6.11) on centos server (6.7), i'm stuck on problem regarding static files. (i'm new django)

i have looked @ great documentation django provides, few other stackoverflow's posts, no avail.

what check :

  • the problem doesn't seem come django or templates, running development server 'debug = false' , option '--insecure' works fine.
  • it problem alias , directory block added in virtualhost, can't make sense of why doesn't work.
  • gunicorn shouldn't have word in it, doesn't serve static files.

what configuration looks :

1) got project's static files '/var/www/myproject/static' 'collectstatic' command.

2) then, created virtualhosts (where think problem is) :

(first 1 redirection https)

<virtualhost *:80>     serveradmin user@domain.com     servername localhost      serversignature off     rewriteengine on      rewritecond %{server_port} !^443$     rewriterule ^/(.*) https://%{http_host}/$1 [nc,r,l] </virtualhost> 

(second 1 actual work)

<virtualhost *:443>     serveradmin user@domain.com     servername localhost      serversignature off      documentroot /var/www/myproject      alias /static/ "/var/www/myproject/static/"     <directory "/var/www/myproject/static">     order allow,deny     allow     </directory>      proxypass / http://127.0.0.1:8000/ connectiontimeout=150 timeout=300     proxypassreverse / http://127.0.0.1:8000/     proxypreservehost on     proxyset http://127.0.0.1:8000/ connectiontimeout=150 timeout=300      ... here goes ssl , log configuration ... </virtualhost> 

after service restart, static files weren't loaded , had 404 error on get. 'httpd -s' didn't throw error , rest of functionalities of web interface working great.

i tried without ending '/' '/static/' alias seemed problem other people, tried move files directly under /var/www/myproject , have them accessed without alias documentroot...

if want have @ django settings.py (don't know if it's relevant, django guru find wrong there too) :

static_root = '/var/www/myproject/static/' static_url =  '/static/' staticfiles_dirs = (os.path.join(os.path.dirname(__file__),'static',),) 

as templates :

{% load staticfiles %} .... <link href="{% static 'bower_components/bootstrap/dist/css/boostrap.min.css %}" rel="stylesheet"> 

urls.py of project :

from django.conf.urls import patterns, include, url django.shortcuts import redirect django.conf import settings django.conf.urls.static import static  urlpatterns = patterns('',     url(r'^$', lambda x: redirect('/collecte/')),     url(r'^collecte/', include('collecte.urls', namespace="collecte")), ) + static(settings.static_url, document_root=settings.static_root) 

and urls.py of app (named 'collecte'):

from django.conf.urls import patterns, url django.contrib.staticfiles.urls import staticfiles_urlpatterns collecte import views  urlpatterns = patterns('',     url(r'^$', views.index, name='index'),     url(r'^collectes/execution/รน', views.collexecution, name='collexecution'),     ... quite lot of them ... )  # commented line suggestion, present @ start #urlpatterns += staticfiles_urlpatterns 

if feel file missing question relevant, ask , i'll best :).

from django.contrib.staticfiles.urls import staticfiles_urlpatterns helper function works when

debug = true

so instance set debug = true again, restart server , check


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -