Wednesday, March 19, 2008

Django Development Server Style Sheet Configuration

When using style sheets (css), specially when using the Django development server, some adaptations are needed in get both the style sheets and the images served. For this, we need use the media path as defined for the framework.
First the media path must be defined and must differentiate it self:

MEDIA_ROOT = '/path/to/media/'
Now we add/link the path to the media path itself:

if settings.DEBUG:
urlpatterns += patterns('', (r'^media/(?P.*)$', 'django.views.static.serve', {'document_root':'/home/fbenavides/Documents/workspace3dot3/txm/src/txm/media/', 'show_indexes': True}), )

In the given HTML file header (index.html is just an example file), the style sheet link must be added:

<link href="/media/css/bluebusiness.css" rel="stylesheet" type="text/css" />

It is assumed that the media path is as follows:


Thus when calling other style sheets and/or images, these must follow the proper call path.


JKK said...

Thanks a lot!

JKK said...

In the lines
urlpatterns += patterns('', (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root':'/home/fbenavides/Documents/workspace3dot3/txm/src/txm/media/', 'show_indexes': True}), )
The <path> is not escaped so disappears..