Django 重定向到绝对uri时出现问题
我正在尝试重定向到完整的url 当前url是一个绝对uriDjango 重定向到绝对uri时出现问题,django,Django,我正在尝试重定向到完整的url 当前url是一个绝对uri currenturl = request.GET.get('currenturl') #lets say this resolves to http://www.google.com/ return redirect(currenturl) 这会将我发送到一个404错误页面,因为它正在尝试解析以下url http://localhost:8000/accounts/profile/calendar/delete/15/'http://
currenturl = request.GET.get('currenturl') #lets say this resolves to http://www.google.com/
return redirect(currenturl)
这会将我发送到一个404错误页面,因为它正在尝试解析以下url
http://localhost:8000/accounts/profile/calendar/delete/15/'http://www.google.com/'
我将模板中的绝对uri传递到currenturl,并在其周围加上单引号。我必须删除单引号。您应该在这前面加两个斜杠,以明确这是根URL,因此
重定向('//google.com')
。如何使用return redirect(currenturl)编写此代码?我不想像您在示例中那样硬编码域名。谢谢在它前面加上两个斜杠,因此重定向('/'+currenturl)
。错误。将我发送到http://%27http://www.google.com'等等,它看起来像是currenturl
包含单引号(因为它不是“google.com”,而是“'google.com'”)。所以GET参数也有问题。