我怎样才能访问我的'返回'得到参数? Django说请求中没有任何GET数据,但查询字符串看起来像/?back=http://myapp/oauth/authorize?redirect_uri=http://example.com/&response_type=code&client_id=222222.
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return redirect(request.GET.get('back','/'))
答案 0 :(得分:2)
您需要对?back=...
GET参数的值进行url编码。所以而不是:
/?back=http://myapp/oauth/authorize?redirect_uri=http://example.com/&response_type=code&client_id=222222
你应该
/?back=http%3A%2F%2Fmyapp%2Foauth%2Fauthorize%3Fredirect_uri%3Dhttp%3A%2F%2Fexample.com%2F%26response_type%3Dcode%26client_id%3D222222
如果要在Django模板中生成GET参数,可以使用内置的urlencode
模板过滤器。如下所示:
<a href="{{ url 'my_view' }}?back={{ redirect_url|urlencode }}"></a>
如果您使用javascript生成参数,则可以使用内置的encodeURI
method