Django相对URL和https [英] Django relative urls and https

查看:98
本文介绍了Django相对URL和https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django项目使用https作为url的某一部分(/ account /,/ admin /,/ purchase /).



当其中一个页面以https模式,所有相对内部链接{%url foo%}将指向 https:// my_url



但是我不想让这些页面显示为https:home,contacts ...



什么是这种要求的解决方案吗?



执行绝对网址?

  http:// {{domain  

不太好

解决方案

正如Tomasz所说,做到这一点的一个方法是设置中间件,以便根据需要从https重定向到。以下是一个实施 - 这个想法是装饰应该在https下提供的视图,当用户导航到不应该是安全的视图时,中间件将自动重定向到http版本的页面。 p>

I have a Django project using https for certain part of the url (/account/, /admin/, /purchase/).

When on one of this page in https mode, all the relative inner links {% url foo %} will point to https://my_url.

However I do not want to have those pages shown as https :home, contacts ...

What are the solutions for this kind of requirements ?

Enforcing absolute url ?

 http://{{ domain }}{% url foo %} 

is not too nice.

解决方案

As Tomasz suggests, one way to do it is to set up middleware to redirect to and from https as necessary. Here's one implementation - the idea is to decorate those views that should be served under https, and when the user navigates to a view that shouldn't be secure from one that is, the middleware redirects them automatically back to the http version of the page.

这篇关于Django相对URL和https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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