3
votes

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)

I'm returning an HttpResponse on a get request, yet I keep getting an error:

error message

The view housepost.views.ListingPost didn't return an HttpResponse object. It returned None instead.

Where am I going wrong?

2
Sorry, I neglected to post it. But it's there.Michael Tedla
Are you implementing something else like dispatch?JuniorCompressor
@JuniorCompressor Yes, I am.Michael Tedla
is the user logged in,in this case.You have placed a decorator for checking that.Zealous System
@user2190496 For your next questions...You saw it's bad thing omitting relevant infoJuniorCompressor

2 Answers

4
votes

dispatch returns a HttpResponse but you don't return anything when you override it. This is the method that calls get or post and returns the response on their behalf. So the following should work:

def dispatch(self, *args, **kwargs):
    return super(ListingPost, self).dispatch(*args, **kwargs)
1
votes

Your dispatch method needs to actually return the result of calling the superclass method:

return super(ListingPost, self).dispatch(*args, **kwargs)