【发布时间】:2021-11-20 15:15:08
【问题描述】:
我正在尝试将已注册的用户重定向到其他视图。这是views.py的代码
但是当 qs.exists() = true 我得到一个错误 '视图 Lpage.views.homeview 没有返回 HttpResponse 对象。而是返回 None。'
我是初学者,已阅读文档,但无法找到我要去的地方。 谢谢
from django.shortcuts import render, redirect
from django.views import View
from Lpage.forms import SubscriberEntryForm
from Lpage.models import Subscriber
class homeview(View):
def get(self,request):
msg = request.session.get('msg', False)
if(msg):
del(request.session['msg'])
return render(request,'Lpage/index.html')
def post(self, request):
form = SubscriberEntryForm(request.POST or None)
if form.is_valid():
obj = form.save(commit=False)
qs = Subscriber.objects.filter(email__iexact=obj.email)
if qs.exists():
return redirect('messageview')
else:
obj.save()
request.session['msg'] = "msg"
return redirect(request.path)
def messageview(request):
return render(request,'Lpage/messages.html',{})
这是错误信息
ValueError 在 /
视图 Lpage.views.homeview 没有返回 HttpResponse 对象。它返回 None 。
请求方法:POST
请求网址:http://localhost:8000/
Django 版本:3.2.7
异常类型:ValueError
异常值:
视图 Lpage.views.homeview 没有返回 HttpResponse 对象。它返回 None 。
异常位置:C:\Users\Ganesamurthi\anaconda3\lib\site-packages\django\core\handlers\base.py,第 309 行,在 check_response
Python 可执行文件:C:\Users\Ganesamurthi\anaconda3\python.exe
Python版本:3.8.5
Python 路径:
['D:\dreamdoors\dd',
'C:\Users\Ganesamurthi\anaconda3\python38.zip',
'C:\Users\Ganesamurthi\anaconda3\DLLs',
'C:\Users\Ganesamurthi\anaconda3\lib',
'C:\Users\Ganesamurthi\anaconda3',
'C:\Users\Ganesamurthi\anaconda3\lib\site-packages',
'C:\Users\Ganesamurthi\anaconda3\lib\site-packages\win32',
'C:\Users\Ganesamurthi\anaconda3\lib\site-packages\win32\lib',
'C:\Users\Ganesamurthi\anaconda3\lib\site-packages\Pythonwin']
服务器时间:2021 年 9 月 29 日星期三 05:23:43 +0000
Traceback 切换到复制和粘贴视图
C:\Users\Ganesamurthi\anaconda3\lib\site-packages\django\core\handlers\exception.py,第 47 行,在内部
response = get_response(request) …
▶ 本地变量
C:\Users\Ganesamurthi\anaconda3\lib\site-packages\django\core\handlers\base.py,第 188 行,在 _get_response
self.check_response(response, callback) …
▶ 本地变量
C:\Users\Ganesamurthi\anaconda3\lib\site-packages\django\core\handlers\base.py,第 309 行,在 check_response
引发价值错误(…
▶ 本地变量
【问题讨论】:
-
请edit您的问题并分享完整错误回溯,同时修复您的代码缩进。
-
修复了帖子中的缩进。谢谢