Django 1.4 - Redirect to Non-HTTP urls

2019-03-15 09:24发布

We have a view which redirects to a Non-HTTP url scheme. Its used in an iOS app. But since we have upgraded to Django1.4 we are getting a crash when this redirect code is executed. It crashes with

SuspeciousOperation at /myyrlscheme/

Unsafe redirect to URL with scheme appdev:

Following is the code:

if acode and acode.has_key('access_token'):
    if DOMAIN == 'dev.mywebsite.com':
        return HttpResponseRedirect('appdev://fbconnect?token=%s'%(acode['access_token']))
    else:
        return HttpResponseRedirect('app://fbconnect?token=%s'%(acode['access_token']))

I can understand why this crashes as HttpResponseRedirect expects a HTTP(s) url scheme. How do I tell Django that this is a safe url and just blindly redirect?

1条回答
狗以群分
2楼-- · 2019-03-15 09:50

I believe you'll need to have a custom Response object, consider following:

response = HttpResponse("", status=302)
response['Location'] = "appdev://..."
return response
查看更多
登录 后发表回答