Python 当我使用HttpResponseRedirect时,我得到TypeError:quote_from_bytes()在Django中应该是字节
在python中尝试实现自定义的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
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')