Reputation: 489
i want to use css in Django templates..If i give CSS with in the templates it gets working. But i want to use in static serve manner.
settings.py
DEBUG =True
MEDIA_ROOT = 'C:/WorkBase/Python/first/static/'
MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/media/'
TEMPLATE_DIRS = (
'C:/WorkBase/Python/first/templates',
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
'django.template.loaders.eggs.load_template_source',
)
urls.py
from django.conf import settings
if settings.DEBUG:
urlpatterns +=patterns(' ',
(r'^static/(?p<path>.*)$','django.views.static.serve',{'document_root':settings.MEDIA_ROOT}),
)
I got 'unexpected end of pattern' error for above line
<link rel="stylesheet" type="text/css" href="/static/css/style.css"/>
Upvotes: 1
Views: 2530
Reputation: 10502
T. Stone has hit the nail on the head with his answer. Here's what I use, for an example:
if settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{ 'document_root': os.path.join(os.path.dirname(__file__), "static")}),
)
Upvotes: 1
Reputation: 19495
I believe the 'P' to name the pattern needs to be capitalized. r'^static/(?P<path>.*)$'
All of the examples and doc show it capitalized. Python Regex Doc
Upvotes: 4