21👍
Change
return render_to_response('register.html', 'errors':errors)
to
return render_to_response('register.html', {'errors': errors}, RequestContext(request))
6👍
Unfortunately, Django’s render_to_response
shortcut by default uses normal template context, which does not include context processors and all their fancy and useful stuff like STATIC_URL
. You need to use RequestContext
, which does precicely that.
This can be called by using the new render
(available since Django 1.3):
from django.shortcuts import render
return render(request, 'register.html', {'errors':errors})
In Django 1.2 and older, you need to supply the context explicitly:
from django.shortcuts import render_to_response
from django.template import RequestContext
return render_to_response('register.html', {'errors':errors},
context_instance=RequestContext(request))
6👍
In Django 1.4 you should use static
templatetag1.
Try:
{% load staticfiles %}
<link href="{% static "css/main.css" %} ...>
- Alter Django admin change list title text
- How to get pretty output from rest_framework serializer
- Django serialize to JSON
- Django is very slow on my machine
- Variable not found. Declare it as envvar or define a default value
- What's the best way to create a model object in Django?
- There is no South database module 'south.db.postgresql_psycopg2' for your database
- Datetime.strptime () throws 'does not match format' error
- Templating with Javascript or Django?
2👍
I realize this has already been answered but I wanted to provide another answer in the event that STATIC_URL still renders as empty even when using RequestContext.
If you are running the development server remember to start the server with the insecure flag to have the server serve your static files:
python manage.py runserver --insecure
- Retrieving the 'many' end of a Generic Foreign Key relationship in Django
- Login_required decorator in django