没有返回HttpResponse对象。它返回None [英] didn't return an HttpResponse object. It returned None instead
本文介绍了没有返回HttpResponse对象。它返回None的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误地将用户注册到我的网站时,出现以下错误:
When incorrectly registering a user to my site I get this following error:
/ accounts / register /视图帐户中的ValueError。 views.register
没有返回HttpResponse对象。而是返回None。
ValueError at /accounts/register/ The view accounts.views.register didn't return an HttpResponse object. It returned None instead.
views.py:
def register(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
form.save()
return redirect('/accounts')
else:
form = RegistrationForm()
args = {'form': form}
return render(request, 'accounts/reg_form.html', args)
urls.py:
urlpatterns = [
path('', views.home, name="home"),
path('explore/', views.explore, name='explore'),
path('login/', LoginView.as_view(template_name='accounts/login.html'), name='login'),
path('logout/', LogoutView.as_view(template_name='accounts/logout.html'), name='logout'),
path('register/', views.register, name='register'),
path('profile/', views.view_profile, name='profile'),
path('profile/edit/', views.edit_profile, name='profile-edit'),
path('change-password/', views.change_password, name='change_password'),
path('reset-password/', PasswordResetView.as_view(template_name='accounts/reset_password.html'),
name='reset-password'),
path('reset-password/done/', PasswordResetDoneView.as_view(), name='password_reset_done'),
path('reset-password/confirm/<uidb64>/<token>/',
PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
path('reset-password/complete/', PasswordResetCompleteView.as_view(), name='password_reset_complete'),
]
main / urls.py:
main/urls.py:
urlpatterns = [
path('', views.login_redirect, name='login_redirect'),
path('admin/', admin.site.urls),
path('accounts/', include('accounts.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
推荐答案
您应将最后两行上移一级。
You should move the last two lines back one level.
else:
form = RegistrationForm()
args = {'form': form}
return render(request, 'accounts/reg_form.html', args)
这篇关于没有返回HttpResponse对象。它返回None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文