Getting started with Django 1.3 here. Loving the system so far, but struggling on stuff. Also loving stackoverflow for the Q&As. 🙂
I’m currently working on getting logins & registrations working and I’m getting a TemplateSyntaxError with my login view.
Template error
In template /templates/login.html, error at line 9
Caught SyntaxError while rendering: (‘invalid syntax’, (‘/userProfile/views.py’, 47, 52, “\t\treturn render_to_response(‘login.html’, {‘form’: })\n”))
I’ve copy-pasted the code from Django’s auth documentation for a login view:
{% extends "base.html" %}
{% load url from future %}
{% block body-content %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
<form method="post" action="{% url django.contrib.auth.views.login %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% endblock %}
Django is breaking on the following line –
<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
I’ve tried removing the single quotes, adding quotes, removing the future url loading but nothing seems to be working. I’ve read the NoReverseMatch question but it doesn’t seem to apply.
The problem is not in your template but rather in your
views.pyfile, line 47:The
render_to_responsefunction expects a template name (here:login.html) and a dictionary (here:{'form': }). However, your dictionary contains a syntax error: You have provided a key (form) but are missing a value.The correct syntax should be something like: