【发布时间】:2017-12-02 02:59:26
【问题描述】:
在我的 django 应用程序的个人资料页面中有一个按钮,单击该按钮后,我想将其重定向到我的主页。
单击该按钮后,views.py 中的一个函数被映射,该函数工作正常,该函数是:
@require_http_methods(['GET','POST'])
def permanentblock(request,Username):
blocker = MyUser.objects.get(username=request.user.username)
blocked = MyUser.objects.get(username=Username)
a = bl_.objects.create(blocker=blocker,blocked=blocked,myboolean=True)
redirect(reverse('home',kwargs={'id':request.user.id}));
#there is a entry in my urls.py for 'home' variable along with the parameter.
现在,直到函数的倒数第二行,它工作正常,表已更新。但是,显示错误:
ValueError at /account/permanentblock/insta/
The view account.views.permanentblock didn't return an HttpResponse object. It returned None instead.
现在,我不想从这个函数返回任何东西,我只想要一个重定向。这不是重定向到 html 页面的正确方法吗?
请提供有关如何更正此实现的建议。
谢谢。
【问题讨论】:
-
你必须在你的视图中返回
redirect。
标签: html python-3.4 django-1.9