# Setting up SSL in settings.py

**URL:** <https://forum.djangoproject.com/t/setting-up-ssl-in-settings-py/7147>\
**Category:** Deployment\
**Created:** [March 20, 2021, 6:19pm UTC](https://forum.djangoproject.com/t/setting-up-ssl-in-settings-py/7147 "2021-03-20T18:19:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![OmidShojaee](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/omidshojaee/32/2216_2.png) [@OmidShojaee](https://forum.djangoproject.com/u/OmidShojaee)\
**Post date:** [March 20, 2021, 6:19pm UTC](https://forum.djangoproject.com/t/setting-up-ssl-in-settings-py/7147/1 "2021-03-20T18:19:07Z")

</div>

Hello,

I have SSL certificate installed on my web server.  
Web server is configured to redirect `http` to `https`.

I have the following parameters in my `settings.py`:

```auto
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_HSTS_SECONDS = 31536000

```

Anything else is required?

---

<div class="post-metadata">

**Author:** ![marcorichetta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/marcorichetta/32/26473_2.png) [@marcorichetta](https://forum.djangoproject.com/u/marcorichetta)\
**Post date:** [March 20, 2021, 11:18pm UTC](https://forum.djangoproject.com/t/setting-up-ssl-in-settings-py/7147/2 "2021-03-20T23:18:15Z")

</div>

You can look here to see Django settings related to SSL/HTTPS.  
[https://docs.djangoproject.com/en/3.1/topics/security/#ssl-https](https://docs.djangoproject.com/en/3.1/topics/security/#ssl-https)

---

<div class="post-metadata">

**Author:** ![OmidShojaee](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/omidshojaee/32/2216_2.png) [@OmidShojaee](https://forum.djangoproject.com/u/OmidShojaee)\
**Post date:** [March 21, 2021, 11:42am UTC](https://forum.djangoproject.com/t/setting-up-ssl-in-settings-py/7147/3 "2021-03-21T11:42:54Z")

</div>

Where do you think I’ve got those parameters?

People on this site are very interesting. The ONLY thing they know is how to post a link to Django documentation!

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 21, 2021, 3:01pm UTC](https://forum.djangoproject.com/t/setting-up-ssl-in-settings-py/7147/4 "2021-03-21T15:01:44Z")

</div>

I’m curious, why do you think we should rewrite or copy/paste the documentation when the specific answer to a question is in that documentation?

You asked the question:

> [@OmidShojaee](#):
>
> Anything else is required?

The documentation linked to so kindly by @marcorichetta answers your question. If you’re having a specific problem with something in that document, you can always ask for clarification here. But yes, the expectation is that you will do your part and read it first.

> [@OmidShojaee](#):
>
> The ONLY thing they know is how to post a link to Django documentation!

In your particular case, your comment is factually incorrect considering the following:

> [@Is it a bad idea to develop my project directly on production server?](https://forum.djangoproject.com/t/is-it-a-bad-idea-to-develop-my-project-directly-on-production-server/4817):
>
> and if not, from security perspective what should I do - besides disabling the debug mode - when development is finished?

> [@Convert view to class-based](https://forum.djangoproject.com/t/convert-view-to-class-based/6457):
>
> Hi, I prefer to learn things by example. Here’s my current view to retrieve a single post: def post\_detail(request, year, month, day, post): post = get\_object\_or\_404(Post, slug=post, status='published', publish\_\_year=year, publish\_\_month=month, publish\_\_day=day) return render(request, 'blog/post/detail.html', {'post': post}) How to convert it to class-based?

> [@Form saves an empty row in the database](https://forum.djangoproject.com/t/form-saves-an-empty-row-in-the-database/5808):
>
> Hello, I have a simple “newsletter” signup form. It is defined as below: The model is created like this: class Subscriber(models.Model): email = models.EmailField(max\_length=254) def \_\_str\_\_(self): return self.email This is the form to subscribe: \<form action="" id="newsletterForm" method="post" role="form"\> {% csrf\_token %} \<input type="email" name="email" required\>\<input type="submit" value="Subscribe"\> …

> [@Trailing slash is missing](https://forum.djangoproject.com/t/trailing-slash-is-missing/5643):
>
> Hello, I’m writing a Blog app with the help of a book. I have this in my urls.py: path('\<int:year\>/\<int:month\>/\<int:day\>\<slug:post\>/', views.post\_detail, name='post\_detail'), and in the models.py this function generates the link to each blog post: def get\_absolute\_url(self): return reverse('blog:post\_detail', args=[self.publish.year, self.publish.month, self.publish.day, self.slug]) However, the link is generated like “2020/12/9slug” not “2020/12/9/slug”. As far as I know, the reverse …

> [@No SITE\_ROOT in settings.py](https://forum.djangoproject.com/t/no-site-root-in-settings-py/4803):
>
> Hello, In many tutorials they talk about PROJECT\_PATH, but I don’t have it in my settings.py, neither I can find it in the official documentation. Is this depreciated? If not, how it should be defined?

> [@Have just one base.html and static folder shared between all apps?](https://forum.djangoproject.com/t/have-just-one-base-html-and-static-folder-shared-between-all-apps/4773):
>
> Hello, I need to have just one base.html template shared between all apps. What I’m thinking now is to have a “templates” folder under project, and put the base.html inside that. For each app I’ll follow the standard method (appname/templates/appname). But I don’t know how to put that into work.

> [@NoReverseMatch after switching to generic views](https://forum.djangoproject.com/t/noreversematch-after-switching-to-generic-views/4739):
>
> Hello, I am following [this tutorial](https://docs.djangoproject.com/en/3.1/intro/tutorial04/) After switching to generic views, I receive NoReverseMatch The error message: Reverse for ‘vote’ with arguments ‘(1,)’ not found. 1 pattern(s) tried: [‘polls/\<int:question\_id/vote/$’] And the error line is 5. \<h1\>{{ question.question\_text }}\</h1\> 2 3 {% if error\_message %}\<p\>\<strong\>{{ error\_message }}\</strong\>\</p\>{% endif %} 4 5 \<form action="{% url 'polls:vote' question.id %}" method=post\> 6 {% csrf\_token %} 7 {% for choice in question.choice\_set.all …

---

<div class="post-metadata">

**Author:** ![OmidShojaee](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/omidshojaee/32/2216_2.png) [@OmidShojaee](https://forum.djangoproject.com/u/OmidShojaee)\
**Post date:** [March 21, 2021, 3:56pm UTC](https://forum.djangoproject.com/t/setting-up-ssl-in-settings-py/7147/5 "2021-03-21T15:56:24Z")

</div>

First, the documentation is the first step for every developer! When people come here and ask question, it is obvious that something is not clear!!! The problem is, you guys don’t have any real-world experience and all you know is what is written in the documentation!!!

For example in the documentation there is `SECURE_SSL_REDIRECT` which is absolutely NOT necessary in my setup because I do that on `ngnix` level! So if I follow the documentation only, I would have it in my settings while it has no use and propably creates issues instead of being useful!

All my questions which you have mentioned are real-case scenarios and none of them are explained in the documentation! From 1992 when I started to learn Turbo Pascal till now my only reference are books and later online tutorials and Django’s is the worst one EVER!

So, from now on please stay away from my topic if all you know is how to post a link!

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 21, 2021, 4:32pm UTC](https://forum.djangoproject.com/t/setting-up-ssl-in-settings-py/7147/6 "2021-03-21T16:32:02Z")

</div>

> [@OmidShojaee](#):
>
> So if I follow the documentation only, I would have it in my settings while it has no use and propably creates issues instead of being useful!

See [SECURE\_SSL\_REDIRECT](https://docs.djangoproject.com/en/3.1/ref/settings/#std:setting-SECURE_SSL_REDIRECT) for the caveats when using it in an environment for which it’s not needed.

> [@OmidShojaee](#):
>
> So, from now on please stay away from my topic if all you know is how to post a link!

We’re building a knowledge base here. We’re not just answering questions for your immediate needs but also for those coming along later and looking for information.  
If a general question is best-answered by a link to the documentation, then yes, I’m going to supply an answer as a link to the relevant page.  
If a question is asked in sufficient detail such that it’s clear that the documentation has been referenced and the question identifies a specific issue needing to be addressed, then I’m more likely to provide supplemental information.

I would also suggest that you try to moderate your “tone” some. Comments about people are not appropriate here. See [the FAQ](https://forum.djangoproject.com/faq) and the related [Django Code of Conduct](https://www.djangoproject.com/conduct/)

---

<div class="post-metadata">

**Author:** ![marcorichetta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/marcorichetta/32/26473_2.png) [@marcorichetta](https://forum.djangoproject.com/u/marcorichetta)\
**Post date:** [March 21, 2021, 11:48pm UTC](https://forum.djangoproject.com/t/setting-up-ssl-in-settings-py/7147/8 "2021-03-21T23:48:27Z")

</div>

I really appreciate your clarification, @KenWhitesell.

> [@OmidShojaee](#):
>
> Anything else is required?

If your question had been more detailed, maybe I would not have answered with just a link.@OmidShojaee

---

<div class="post-metadata">

**Author:** ![connektiv8](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/connektiv8/32/26912_2.png) [@connektiv8](https://forum.djangoproject.com/u/connektiv8)\
**Post date:** [February 14, 2025, 4:22am UTC](https://forum.djangoproject.com/t/setting-up-ssl-in-settings-py/7147/10 "2025-02-14T04:22:53Z")

</div>

Agreed, and I’m now reading a 4-year-old argument instead of getting a reference to a link that might have been helpful instead of trawling through old garbage hoping to find the gem of knowledge! It was helpful though, just finding the answer is a lot harder when you have to sift through off-topic dialogue.
