Django 1.4 - 重定向到非HTTP网址 [英] Django 1.4 - Redirect to Non-HTTP urls

查看:276
本文介绍了Django 1.4 - 重定向到非HTTP网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个视图重定向到非HTTP URL方案。它用于iOS应用程序。但是,由于我们升级到Django1.4,所以当这个重定向代码被执行时,我们会遇到崩溃。它崩溃与

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


/ myyrlscheme /

SuspeciousOperation at /myyrlscheme/

不安全重定向到URL方案appdev:

Unsafe redirect to URL with scheme appdev:

以下是代码:

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']))

我可以理解为什么崩溃为 HttpResponseRedirect code> HTTP(s) url方案。如何告诉Django这是一个安全的URL,只是盲目重定向?

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?

推荐答案

我相信你需要有一个自定义响应对象,请考虑以下内容:

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

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

这篇关于Django 1.4 - 重定向到非HTTP网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆