When I use HttpResponseRedirect I get TypeError: quote_from_bytes() expected bytes in Django

Viewed 6523

When trying to implement a custom get_success_url method in python, Django throws a TypeError: quote_from_bytes()error. For example:

class SomeView(generic.CreateView):

    #... 

    def get_success_url(self):
        return HttpResponseRedirect(reverse('index'))
2 Answers

get_success_url doesn't return an HttpResponseRedirect instead it should return the url you want to redirect to. So you can just return reverse('index'):

def get_success_url(self):
    return reverse('index')

A shortcut for HttpResponseRedirect is redirect("View_name") it returns an HttpResponse (HTML)

Reverse returns a url

Related