Django 1.4 - Redirect to Non-HTTP urls

你。 提交于 2019-12-03 11:55:59

问题


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:


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

response = HttpResponse("", status=302)
response['Location'] = "appdev://..."
return response


来源:https://stackoverflow.com/questions/14558876/django-1-4-redirect-to-non-http-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!