urls.py
from housepost.views import ListingPost
...
url(r'^house_post/$', ListingPost.as_view(), name='post_house'),
...
views.py
from django.http import HttpResponse
from django.contrib import messages
from django.views.generic import View
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
class ListingPost(View):
def get(self, request, *args, **kwargs):
messages.error(request, 'asdf', extra_tags = 'error')
return HttpResponse('Hi')
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
super(ListingPost, self).dispatch(*args, **kwargs)
我在 get 请求上返回 HttpResponse,但仍然收到错误:
错误信息
视图 housepost.views.ListingPost 未返回 HttpResponse 对象。它返回 None 相反。
我哪里错了?
dispatch
返回一个HttpResponse
但当你重写它时,你不会返回任何东西。这是调用的方法get
or post
并代表他们返回响应。所以以下应该有效:
def dispatch(self, *args, **kwargs):
return super(ListingPost, self).dispatch(*args, **kwargs)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)