4

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?

5
  • Sorry, I neglected to post it. But it's there. Commented Apr 20, 2015 at 10:01
  • Are you implementing something else like dispatch? Commented Apr 20, 2015 at 10:04
  • @JuniorCompressor Yes, I am. Commented Apr 20, 2015 at 10:08
  • is the user logged in,in this case.You have placed a decorator for checking that. Commented Apr 20, 2015 at 10:09
  • @user2190496 For your next questions...You saw it's bad thing omitting relevant info Commented Apr 20, 2015 at 10:11

2 Answers 2

4

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)
Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.