Ananth
Ananth

Reputation: 55

how to serve static files in django development server

this question has been answered several times and i have seen almost all related posts,but couldn't get css files load. i have this structure in my project: mysite /templates /settings.py /urls.py /myapp /static /css /test.css in settings.py i have this code:

import os
PROJECT_PATH=os.path.realpath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(PROJECT_PATH,'static',)
STATIC_URL = '/static/'

in urls.py i have this code:

from django.conf.urls.defaults import*
from mysite.myapp.views import test
urlpatterns = patterns('',(r'^home/$',test),)

from django.conf import settings
if settings.DEBUG:
    urlpatterns += patterns('django.contrib.staticfiles.views',
                        url(r'^static/(?P<path>.*)$','serve'),
                        )

i use this in the template

{{STATIC_URL}}css/test.css

what wrong am i doing? is there anything should i be doing?like should add anything in STATICFILES_DIRS? or in INSTALLED_APPS in settings? kindly assume that i am an absolute beginner. i really need an answer. thank you.

Upvotes: 1

Views: 456

Answers (1)

JoshuaBox
JoshuaBox

Reputation: 775

you still need to pass STATIC_URL to the template in your view. The easiest way to do this is using RequestContext as long as the 'TEMPLATE_CONTEXT_PROCESSORS' include the static entry.

Upvotes: 1

Related Questions