Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当我使用HttpResponseRedirect时,我得到TypeError:quote_from_bytes()在Django中应该是字节_Python_Django - Fatal编程技术网

Python 当我使用HttpResponseRedirect时,我得到TypeError:quote_from_bytes()在Django中应该是字节

Python 当我使用HttpResponseRedirect时,我得到TypeError:quote_from_bytes()在Django中应该是字节,python,django,Python,Django,在python中尝试实现自定义的get\u success\u url方法时,Django抛出一个TypeError:quote\u from\u bytes()错误。例如: class SomeView(generic.CreateView): #... def get_success_url(self): return HttpResponseRedirect(reverse('index')) get\u success\u url不会返回HttpR

在python中尝试实现自定义的
get\u success\u url
方法时,Django抛出一个
TypeError:quote\u from\u bytes()
错误。例如:

class SomeView(generic.CreateView):

    #... 

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

get\u success\u url
不会返回HttpResponseRedirect,而是应该返回要重定向到的url。因此,您只需返回
reverse('index')


HttpResponseRedirect的快捷方式是重定向(“视图名称”) 它返回一个HttpResponse(HTML)

反向返回一个url

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