首页 > 解决方案 > django HttpResponse 位置重定向

问题描述

True当我添加了http 响应response['Location'] = 'login.html'但它不起作用时,我试图重定向到另一个页面,我得到一个包含True书面但不是登录页面的页面。你能帮我吗我是django的新手。

我写了这段代码

if user_obj:
    response = HttpResponse(True)
    response['Location'] = 'login.html'
    return response
else:
    return HttpResponse(False)

标签: pythondjango

解决方案


从 django.urls 导入反向

返回 HttpResponseRedirect(reverse('url_name'))


推荐阅读