Django重定向到自定义网址

编程入门 行业动态 更新时间:2024-10-26 13:21:05
本文介绍了Django重定向到自定义网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

为了给你一些上下文,如果它有帮助,我有一个使用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(例如www.yahoo/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. 'www.yahoo/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.

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

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

It should work anyway from what I'm reading.

更多推荐

Django重定向到自定义网址

本文发布于:2023-10-04 16:02:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467189.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   重定向   网址   Django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!