What Is Wrong With This Code In Settings.py File Of My Django Application?
Solution 1:
In development you have to add a specific URL pattern to your urls in urls.py
.
The Django docs talk about this in detail here.
Note that you should disable this url in production. So enable the URL pattern only in development, by doing for instance:
if settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATICFILES_DIRS[0], 'show_indexes': True}),
)
assuming the first STATICFILES_DIRS
directory is the one containing your CSS (and other static files).
In production it is suggested to never serve static files via Django; do it via Apache or better, Nginx.
Solution 2:
Normally, there is no need to specify if settings.DEBUG:
and lines below it: they are automatically loaded w/ staticfiles
installed and runserver
in DEBUG mode.
What you need to do is to make the STATICFILES_FINDERS
to find the css file. For the two defined in you settings.py
: FileSystemFinder
searches dirs in STATICFILES_DIRS
, AppDirectoriesFinder
searches for the css in installed apps.
Thus, copy the file to /var/dj/oneliners/static
or some_installed_app/static
will do the trick. Note that before you start to collect statics to STATIC_ROOT
, you could simply leave STATIC_ROOT=''
, and, STATIC_ROOT
should be different from dirs defined in STATICFILES_DIRS
(could contain) because they're different in logic.
Solution 3:
add this to your urlpatterns, it works for me (r'^css/(?P.*)$', 'django.views.static.serve', {'document_root': '/xxx/WebRoot/css'}),
Post a Comment for "What Is Wrong With This Code In Settings.py File Of My Django Application?"