I have a project with all HTTP requests and responses(url). I need to convert it to HTTPS. Is there any way to achieve this in django ?
Asked
Active
Viewed 6,024 times
2 Answers
4
Usually your templates are agnostic regarding the protocol scheme, as you rely on the url template tag. If you want to enforce django to redirect everything to SSL you might want to set SECURE_SSL_REDIRECT in your settings.
Everything else is related to your webserver configuration - which needs a valid certificate and a corresponding configuration. Here is a sample for nginx
dahrens
- 3,879
- 1
- 20
- 38
2
This is something that is usually handled in webserver, not django code itself. (Although you can do it simply with a middleware or using SECURE_SSL_REDIRECT settings option as mentioned by @dahrens)
For example, ngnix configuration that redirects all http requests to https is as follows:
server {
listen 80;
return 301 https://$server_name$request_uri;
}
Mohammad Jafar Mashhadi
- 4,102
- 3
- 29
- 49