Skip to content Skip to sidebar Skip to footer

Django Relative Urls And Https

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 %

Solution 1:

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.

Solution 2:

Idea: you can use a custom middleware to redirect from https to http (or vice versa) for centrain URLs or URL patterns. This could also be done in Apache (or other web server) configuration.

Solution 3:

Could use your webserver to rewrite to http, that way Django doesn't even need to know.

Solution 4:

I find this snippet takes care of the situation nicely. Views that need SSL will have them, via a redirect from the http to https version of the url, and vice-versa.

Yes, on a https page, the outbound link to a non-https page in your site will still start with https, but the user will be redirected to the http version.

(There is a gotcha, however: it won't work if you're posting from http to https and vice versa)

Solution 5:

maybe this can serve for you

http://code.djangoproject.com/wiki/ContributedMiddleware#SSLMiddlewarebyStephenZabel

an contributed SSL Middleware

Post a Comment for "Django Relative Urls And Https"