python - 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)
解决方案
从 django.urls 导入反向
返回 HttpResponseRedirect(reverse('url_name'))
推荐阅读
- angular - 如果 HTTP 错误代码为 500,则 Angular 重新尝试 API 请求
- freemarker - Freemarker - 用户定义指令调用的动态名称
- python - 在张量流中计算新状态(RNN)相对于模型参数(包括输入的 CNN)的梯度;tf.gradient 返回无
- excel - 当宏在另一个工作簿中运行时,如何打开工作簿?
- javascript - React Hooks:跨函数访问状态而不更改事件处理函数引用
- sql - 使用 X 和 U 锁在同一张表上发生死锁
- r - R 中的合法列名和语法无效列名的后果
- c# - .Net Core Enumeration 问题使用 FromRoute 和 EnumMember
- angular - Angular 7 检测浏览器选项卡已激活
- javascript - 在 React 项目的公共文件夹中创建/保存文件