作业有什么问题
怎么了?
email_change_view 中的文件“trunk/website/auth/user/emailchange/views.py”
<代码>102。 context['form'] = 表单__setitem__ 中的文件“/usr/local/lib/python2.6/dist-packages/django/template/context.py”
<代码>39。 self.dicts[-1][key] = value
异常类型:TypeError at /accounts/email/change/
异常值:“SendUsernameForm”对象不支持项目分配
这里是代码
else:
form = EmailChangeForm(username=request.user.username)
context = RequestContext(request, extra_context)
context['form'] = form
return render_to_response(template_name, context_instance=context)
HTML 代码:
<form method="post">{% csrf_token %}
{{ form.as_p }}
<p><input type="submit" value="Change email address" /></p>
</form>
有什么想法吗?
what's wrong?
File "trunk/website/auth/user/emailchange/views.py" in email_change_view
102. context['form'] = form
File "/usr/local/lib/python2.6/dist-packages/django/template/context.py" in __setitem__
39. self.dicts[-1][key] = value
Exception Type: TypeError at /accounts/email/change/
Exception Value: 'SendUsernameForm' object does not support item assignment
Here is the Code
else:
form = EmailChangeForm(username=request.user.username)
context = RequestContext(request, extra_context)
context['form'] = form
return render_to_response(template_name, context_instance=context)
HTML Code:
<form method="post">{% csrf_token %}
{{ form.as_p }}
<p><input type="submit" value="Change email address" /></p>
</form>
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
form
添加到extra_context
dic,而不是context
。该错误的字面意思是,
context['form']
无效,因此这是一个开始思考是否应该以这种方式使用 RequestContext 的好地方。RequestContext 文档: http://docs.djangoproject.com /en/dev/ref/templates/api/#django.template.RequestContext
Add
form
toextra_context
dic, notcontext
.The error is literally saying,
context['form']
is invalid, so it's a good place to start wondering if RequestContext should be used in that fashion.RequestContext docs: http://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.RequestContext