用户creationform验证不起作用django
一切似乎都可以正常工作,但是如果表单没有验证,而不是获得HTML验证错误,我会得到 valueerror ar /register /:user.register不会返回httpresponse。它没有返回。
我的代码:
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
messages.success(request, 'Acount created!')
else:
form = UserCreationForm():
return render(request, 'users/register.html', {"form":form})
Everything seems to be working fine, but if the form doesn't validate, instead of getting HTML validation errors, I get ValueError ar /register/: The user.register didn't return an HTTPResponse. It returned none instead.
My code:
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
messages.success(request, 'Acount created!')
else:
form = UserCreationForm():
return render(request, 'users/register.html', {"form":form})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,在每个API调用上返回响应,
例如
尝试根据django的任何响应添加返回语句,根据您尝试返回的内容,
您需要在块上添加类似的响应
。 com/tutorial/2016/07/27/how-to return-json-json-jsoded-response.html#:%7E:text = text = after%20version%201.7%2c%20django%20counts,在%20 returning%20%20%20%20 response%之前20object“ rel =” nofollow noreferrer> https://simpleisbetterthancomplex.com/tutorial/2016/07/07/27/how-to-to-to-to-to-wo--return-json-json-conconded-response.html#:tmo- 2C%20DJANGO%20counts,在%20返回%20%20 response%20Object 之前。
usually response are returned on each api call
like
try to add return statement with any of Response from django based on what you try to return
you need to add similar to this on if block
refer : https://simpleisbetterthancomplex.com/tutorial/2016/07/27/how-to-return-json-encoded-response.html#:~:text=Since%20version%201.7%2C%20Django%20counts,before%20returning%20the%20response%20object.