Django重定向到自定义网址 [英] Django redirect to custom URL

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

问题描述

从我的Django应用程序,如何将用户重定向到somescheme://someurl.com?

From my Django app, how to I redirect a user to somescheme://someurl.com?

为了给你一些上下文,如果它有帮助,我有一个使用Python / Django编写的工作的oauth2服务器,我需要允许用户注册具有自定义URL方案的redirect_uris。此自定义URL方案用于处理本机应用程序中的重定向

To give you some context in case it helps, I have a working oauth2 server written in Python/Django and I need to allow users to register redirect_uris that have a custom URL scheme. This custom URL scheme is used for handling the redirect within native apps.

我的第一反应是使用HttpResponseRedirect,但是这个URL一个自定义方案,不是HTTP,所以我猜这不是我想要的。感谢您提前提供的任何建议。

My first reaction was to use an HttpResponseRedirect, but this URL has a custom scheme and isn't HTTP so I'm guessing this is not what I want. Thanks in advance for any advice you can give.

编辑:
我尝试过这个,Django正确地返回响应重定向,而不会抛出错误,但浏览器不会重定向到此网址。我正在使用Chrome来测试这个。

I did try this and Django returns the response redirect correctly without throwing an error, but the browser does not redirect to this URL. I'm using Chrome to test this.

编辑2:
HttpResponseRedirect在safari中工作正常。

Edit 2: HttpResponseRedirect works fine in safari.

推荐答案


class HttpResponseRedirect

class HttpResponseRedirect

构造函数的第一个参数是必需的 - 重定向的路径至。这可以是一个完全限定的URL(例如http://www.yahoo.com/search/),也可以是no> domain(例如'/ search /')的绝对路径。有关其他可选构造函数参数,请参阅HttpResponse。注意>这返回一个HTTP状态代码302.

The first argument to the constructor is required -- the path to redirect to. This can >be a fully qualified URL (e.g. 'http://www.yahoo.com/search/') or an absolute path with no >domain (e.g. '/search/'). See HttpResponse for other optional constructor arguments. Note >that this returns an HTTP status code 302.

这是从这里:
https://docs.djangoproject.com/en/dev/ref/request-response/

它应该从我正在阅读的方面工作。

It should work anyway from what I'm reading.

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

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