Django 1.3 rc1 and CSS
This is my configuration:
project_root
- (init, urls, settings, manage etc.).py
- templates
- - - <html files>
- - - <css files>
- - - <images>
- mainapp
my settings.py:
DEBUG = True
TEMPLATE_DEBUG = DEBUG
...
STATIC_ROOT = 'c:/static_collect/'
...
STATIC_URL = '/static/'
...
STATICFILES_DIRS = (
'c:/django-projects/myproject/mainapp/templates',
)
...
TEMPLATE_DIRS = ('c:/django-projects/myproject/mainapp/templates',)
my template references CSS files with {{ STATIC_URL}}style.css.
Everything works in development server. I view my CSS, static images and everything else.
Now I'm preparing to deploy a project, so I'm experimenting a little, before buying a hosting. Launched manage.py collectstatic and all of my static files in 开发者_开发技巧STATICFILES_DIRS were correctly copied to c:/static_collect.
I switched Debug = False to Debug = True. And my website doesn't load the stylesheet. I'm going crazy on this... templates are loaded but static files are simply not reachable.
Are not you allowed to put Debug=False in the development server? Will it be solved once I put the project on a real production server? Any ideas?
Thank you for your time.
The static files aren't added to the url patterns when debug is set to False. See staticfiles/urls.py:
if settings.DEBUG and not urlpatterns:
urlpatterns += staticfiles_urlpatterns()
You'll need to setup apache to serve the files, or add the urlpatterns yourself when debug is False (not recommended).
精彩评论