deployment - Django MEDIA_URL again ... Unhandle -


my settings.py file

media_root = '/home/path/to/htdocs/mysite/public/media/' media_url = '/site_media/' admin_media_prefix = '/media/' 

in site_media have images , css ...href="{{ media_url }}/style.css" ... (with {{ media_url }}style.css same)

after render href="/site_media/style.css"

but @ http://example.com/site_media/style.css there unhandled exception (i thing no url mapped in urls.py)

everything work fine in debug mode because have in urls.py

if settings.debug:     urlpatterns += patterns('',     (r'^media/(.*)$', 'django.views.static.serve', {'document_root': os.path.join(os.path.dirname(__file__), 'media')}),     (r'^site_media/(.*)$', 'django.views.static.serve', {'document_root': os.path.join(os.path.dirname(__file__), 'site_media')}), ) 

but need when debug = false

what happening in debug mode django serves style.css file. tell line

(r'^site_media/(.*)$', 'django.views.static.serve', {'document_root': os.path.join(os.path.dirname(__file__), 'site_media')}), 

)

but line not go urlpatterns variable when debug false. test try access localhost:8000/site_media/style.css when debug true (should work) , when false (will give 404 error).

you leave out

if settings.debug: 

part, means django still serve static files , not recommended in production performance reasons.

in production setup should use different webserver serve static files. have had experiences nginx running in front of apache.

this excellent tutorial shows how create such setup: http://www.ventanazul.com/webzine/tutorials/django-deployment-guide-ubuntu

be prepared though creating production setup not quite painless typing python manage.py runserver. have heard things using nginx gunicorn , that makes setting production server simpler, have no experience myself.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -