Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.4 - Redirect to Non-HTTP urls

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?

like image 509
Srikar Appalaraju Avatar asked Jan 28 '13 09:01

Srikar Appalaraju


1 Answers

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

response = HttpResponse("", status=302)
response['Location'] = "appdev://..."
return response
like image 94
migajek Avatar answered Oct 13 '22 22:10

migajek