2012-01-04 30 views
0

這裏開始使用Django 1.3。目前爲止熱愛這個系統,但是在努力工作。也喜歡Q & As的stackoverflow作爲。 :)帶有django.contrib.auth.views.login的TemplateSyntaxError

我目前正在努力獲取登錄&註冊工作,我得到一個TemplateSyntaxError與我的登錄視圖。

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"))

我複製粘貼從Django的權威性文件的代碼登錄的看法:

{% 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是以下行打破 -

<form method="post" action="{% url 'django.contrib.auth.views.login' %}"> 

我試着刪除單引號,添加引號,刪除未來的網址加載,但似乎沒有任何工作。我讀過NoReverseMatch question,但它似乎並不適用。

+2

它說你有你'views.py'錯誤?有SyntaxError,而不是NoReverseMatch。 – demalexx 2012-01-04 04:03:02

回答

0

的問題是不是在你的模板,而是在你的views.py文件,第47行:

return render_to_response('login.html', {'form': }) 

render_to_response功能需要一個模板名稱(這裏:login.html)和字典(這裏:{'form': })。但是,您的字典包含語法錯誤:您提供了一個密鑰(form),但缺少一個值。

的正確語法應該是這樣的:

return return render_to_response('login.html', {'form': my_form}) 
+0

令人沮喪的事情是,我曾這樣做:\t 'return render_to_response('/ registration/login.html',{'form':form,})' 我從操作中刪除了網址(用「。」代替。 )和我的看法工作。 – serpah 2012-01-05 06:01:12

0

像demalexx寫的問題是在userProfile/views.py。根據錯誤消息,它看起來像你的上下文字典是無效的。關鍵'形式'沒有得到它的價值。

相關問題