I am new to django but have some relative skills in python. I just started building a project in django and so far I have been able to create an app within my project. Also, I h
Thanks to all those that responded to my question, my static files are now active. I had to add RequestContext in my project view to make the {{STATIC_URL}} in the html file active.
def index(request): return render_to_response('Calculator/index.html', context_instance=RequestContext(request))
Just a small demo for very basic css/img usage with the development-server: python manage.py runserver
. You should not use this for production.
For the user input/output you should have a look at the tutorial.
filestructure
project
|- static
| |- css
| | |- stuff.css
|- media
| |- images
| | |- love.jpg
|- templates
|- urls.py
|- __init__.py
|- manage.py
|- settings.py
base.html
<html>
<head>
<link href="{{ STATIC_URL }}css/stuff.css" />
</head>
<body>
<h1>I like django!</h1>
<img src="{{ MEDIA_URL }}images/love.jpg" />
</body>
</html>
settings.py
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages',
)
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
urls.py
# example windows
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': 'C:/python25/lib/site-packages/project/media/', 'show_indexes': True}),
# example *ix
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': '/usr/lib/python25/site-packages/project/static/', 'show_indexes': True}),