python - Django static files when locally developing - how to serve absolutely? -
this should super simple, somehow has had me stuck morning. i'm developing locally, using django debug server, , filestructure:
/project/ (django project) /static/ (static files)
in settings.py media_root , media_url both set '/static/' , i'm using in urls.py
url(r'^(?p<path>.*)$', 'django.views.static.serve', {'document_root': '../static'}),
in templates, files need server static directory configured such:
<link rel="stylesheet" href="{{ static_url }}css/style.css">
that works should - javascript/css/images served hompage. however, when go subdirectory, such http://127.0.0.1:8000/news/ links broken.
i've tried using variety of os.import options relative links properly, havent had luck. there way force relative base url, or perhaps hardcode filesystem?
any amazing!
in line in urls.py file, '../static'
should changed absolute directory. try changing , see happens.
your file:
url(r'^(?p<path>.*)$', 'django.views.static.serve', {'document_root': '../static'}),
should more like:
url(r'^(?p<path>.*)$', 'django.views.static.serve', {'document_root': '/full/path/to/static'}),
to give example, mine set little differently, still use full path.
here's how mine setup: in settings.py
static_doc_root = '/users/kylewpppd/projects/django/kl2011/assets/'
and in urls.py
:
(r'^assets/(?p<path>.*)$', 'django.views.static.serve', {'document_root': settings.static_doc_root, 'show_indexes':true}),
i'm serving static files 'localhost:8000/assets/'
.
Comments
Post a Comment