{"id":942,"date":"2019-04-08T13:39:38","date_gmt":"2019-04-08T10:39:38","guid":{"rendered":"https:\/\/djangostars.com\/blog\/?p=942"},"modified":"2025-09-12T12:35:20","modified_gmt":"2025-09-12T12:35:20","slug":"configuring-django-settings-best-practices","status":"publish","type":"post","link":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/","title":{"rendered":"Configuring Django Settings: Best Practices"},"content":{"rendered":"<p>This article is intended for engineers who use the Django framework. It gives a deep insight and best practices into configuring Django project settings, and the pros and cons of different approaches.<\/p>\n<p>In the article, Django settings.py explained, you will also find recommendations concerning tools, best practices, and architectural solutions, all time-tested and proven by successful projects. And if you still have questions after reading it, you can always leave a comment below or use our <a href=\"https:\/\/djangostars.com\/get-in-touch\/\">contact form<\/a>. The article is based on our vast experience with real projects and <a href=\"https:\/\/djangostars.com\/blog\/rest-apis-django-development\/\">Django REST framework<\/a>. Our <a href=\"https:\/\/djangostars.com\/services\/python-django-development\/\">Django agency<\/a> specializes in crafting scalable, secure configurations that adhere to best practices for every environment.<\/p>\n<h2>Managing Django Settings: Issues<\/h2>\n<p><strong>Different environments.<\/strong>\u00a0Usually, you have several environments: local, dev, ci, qa, staging, production, etc. Each environment can have its own specific settings (for example:\u00a0<code>DEBUG = True<\/code>, more verbose logging, additional apps, some mocked data, etc). You need an approach that allows you to keep all these Django setting configurations.<\/p>\n<p><strong>Sensitive data.<\/strong>\u00a0You have\u00a0<code>SECRET_KEY<\/code>\u00a0in each Django project. On top of this there can be DB passwords and tokens for third-party APIs like Amazon or Twitter. This data cannot be stored in VCS.<\/p>\n<p><strong>Sharing settings between team members.<\/strong>\u00a0You need a general approach to eliminate human error when working with the settings. For example, a developer may add a third-party app or some API integration and fail to add specific settings. On large (or even mid-size) projects, this can cause real issues.<\/p>\n<p><strong>Django settings are a Python code.<\/strong>\u00a0This is a curse and a blessing at the same time. It gives you a lot of flexibility, but can also be a problem \u2013 instead of key-value pairs, settings.py can have a very tricky logic.<!-- new --><\/p>\n<h2>Django Secret Key: How to Protect<\/h2>\n<p><code>SECRET_KEY<\/code> is used for cryptographic signing in Django, so it must be kept safe.<\/p>\n<p>Django uses salt stored in the <code>SECRET_KEY<\/code> variable to create hashes of sensitive data. This means anyone who has access to the project\u2019s SECRET_KEY, also has access to all sensitive information.<\/p>\n<p><code>SECRET_KEY<\/code> may be found in the <code>settings.py<\/code> file. It\u2019s usually a variable containing a random string.<\/p>\n<p><b>Note<\/b>: don\u2019t share SECRET_KEY in your project repositories.<\/p>\n<p>To create a new <code>SECRET_KEY<\/code>, use the next command:<\/p>\n<pre><code>django.core.management.utils.get_random_secret_key<\/code><\/pre>\n<p>Then, you need to open a Python shell in the required directory and use the command below:<\/p>\n<pre><code>python3 manage.py shell\r\n\r\nfrom django.core.management.utils import get_random_secret_key\r\nprint(get_random_secret_key())<\/code><\/pre>\n<p>The last thing you must do is copy the generated <code>SECRET_KEY<\/code> and paste it into the <code>settings.py<\/code> file.<!-- . --><\/p>\n<h2>Setting Django Configurations: Different Approaches<\/h2>\n<p>There is no built-in universal way to configure Django settings without hardcoding them. But books, open-source and work projects provide a lot of recommendations and approaches on how to do it best. Let&#8217;s take a brief look at the most popular ones to examine their weaknesses and strengths.<\/p>\n<h3>settings_local.py<\/h3>\n<p>When configuring a new Django project, it\u2019s common to create a local settings template module, which is excluded from version control. The developer can determine which settings are local, but it may not be so convenient because they need to set additional values and ensure they are valid.<\/p>\n<p>If a Django project has only one settings module, the local settings file can define base settings and specify what settings should be local or secret. <!--This is the oldest method. I used it when I was configuring a Django project on a production server for the first time. I saw a lot of people use it back in the day, and I still see it now.\nThe basic idea of this method is to extend all environment-specific settings in the\u00a0<code>settings_local.py<\/code>\u00a0file, which is ignored by VCS.-->Here\u2019s an example:<\/p>\n<p><code>settings.py<\/code>\u00a0file:<br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/b3660bf6112215f9bb93e0f8c0ce0826.js\"><\/script><br \/>\n<code>settings_local.py<\/code>\u00a0file:<br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/39455aac4b238bb4f8e9c097c94105e5.js\"><\/script><\/p>\n<p><!-- new -->Local settings can be situated inside other settings. You can add there doc strings, which are displayed when prompting, and default values required for when prompting.<\/p>\n<p>When the local settings file is created and set up, you may add the following line: <code>inject_settings()<\/code>. This command specify which settings can be considered local and merges them from the settings file.<\/p>\n<p>After <code>inject_settings()<\/code> runs, it\u2019s possible to access the local settings in the settings module For example, if you run <code>if DEBUG<\/code>, then <code>DEBUG<\/code> is no longer in the local settings.<\/p>\n<p>When you run a <code>manage.py<\/code> command, all missing local settings will be prompted to enter. If there are no required files, they will be created.<\/p>\n<h4>Pros:<\/h4>\n<ul>\n<li>Secrets not in VCS.<\/li>\n<\/ul>\n<h4>Cons:<\/h4>\n<ul>\n<li><code>settings_local.py<\/code>\u00a0is not in VCS, so you can lose some of your Django environment settings.<\/li>\n<li>The Django settings file is a Python code, so\u00a0<code>settings_local.py<\/code>\u00a0can have some non-obvious logic.<\/li>\n<li>You need to have\u00a0<code>settings_local.example<\/code>\u00a0(in VCS) to share the default Django configurations for developers.<\/li>\n<\/ul>\n<h3>Separate settings file for each environment<\/h3>\n<p>This is an extension of the previous approach. It allows you to keep all configurations in VCS and to share default settings between developers.<br \/>\n<!--In this case, there are multiple files from which projects on Django get settings, and you make a\u00a0<code>settings<\/code>\u00a0package with the following file structure:--><br \/>\nRunning different environments requires separate settings files. By default, a Django project contains a single <code>settings.py<\/code> file. But creating more of them is possible, giving each a different name. Also, you can make a package to keep all settings files together. Just like that:<\/p>\n<pre><code>settings\/\r\n   \u251c\u2500\u2500 __init__.py\r\n   \u251c\u2500\u2500 base.py\r\n   \u251c\u2500\u2500 ci.py\r\n   \u251c\u2500\u2500 local.py\r\n   \u251c\u2500\u2500 staging.py\r\n   \u251c\u2500\u2500 production.py\r\n   \u2514\u2500\u2500 qa.py<\/code><\/pre>\n<p><!--settings\/local.py:--><br \/>\nOnce you have created multiple settings files, the project&#8217;s manage.py file requires updates \u2014 you must specify the relevant settings file, not the default one.<\/p>\n<p>When multiple settings files are created and set up, you can use them in a Django project. Import a chosen settings file in your code by using the following code:<br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/f275409df9842b6e9598f39a6ea621c1.js\"><\/script><br \/>\n<!--To specify for a project you run which Django configuration file to use, you need to set an additional parameter:--><br \/>\nThe code imports all variables from <code>settings_base.py<\/code> into the module you\u2019re using.<\/p>\n<p>Also, you can specify which settings file you need to use when the Django application starts. For example, if you need to use local settings, run the application using the following command:<br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/51a4fe47c3ebbaea81ead91448edc765.js\"><\/script><br \/>\n<!--new-->So, the system will start an app with a settings_local.py file, not a default one.<\/p>\n<p>Next, consider the option when you have to override some specific settings in a settings file. It may be helpful to use different databases for production and development environments.<\/p>\n<p>To do it, you need to redefine settings in the required settings file. For example, the project uses SQLite for the development environment and PostgreSQL for production. In such a case, you must define a different database for each environment in each respective settings file.<\/p>\n<pre><code># settings_dev.py\r\nDATABASES = {\r\n    'default': {\r\n        'ENGINE': 'django.db.backends.sqlite3',\r\n        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),\r\n    }\r\n}\r\n\r\n# settings_prod.py\r\nDATABASES = {\r\n    'default': {\r\n        'ENGINE': 'django.db.backends.postgresql',\r\n        'NAME': 'database',\r\n        'USER': 'user',\r\n        'PASSWORD': 'password',\r\n        'HOST': 'host',\r\n        'PORT': '',\r\n    }\r\n}<\/code><\/pre>\n<p><!--.--><\/p>\n<h4>Pros:<\/h4>\n<ul>\n<li>All environments are in VCS.<\/li>\n<li>It&#8217;s easy to share settings between developers.<\/li>\n<\/ul>\n<h4>Cons:<\/h4>\n<ul>\n<li>You need to find a way to handle secret passwords and tokens.<\/li>\n<li>&#8220;Inheritance&#8221; of settings can be hard to trace and maintain.<\/li>\n<\/ul>\n<h3>Environment variables<\/h3>\n<p><!--To solve the issue with sensitive data, you can use environment variables in Django.-->Django variables may be used to secure sensitive data, such as passwords, secret keys, API IDs, etc.<\/p>\n<p>There are two things you must remember:<\/p>\n<ul>\n<li>\n<ol>Make sure you don\u2019t use quotations around strings.<\/ol>\n<ol>Make sure you don\u2019t use spaces on both sides of the assignment operator.<\/ol>\n<\/li>\n<\/ul>\n<p>The list of variables may be as long as your project needs. After listing variables in the <code>.env<\/code> file, you can replace explicit values in the <code>settings.py<\/code> file with those from the Django environment variables file.<!--.--><br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/00ba08707672541ac8be227d869241a2.js\"><\/script><br \/>\nThis is the simplest example using Python\u00a0<code>os.environ<\/code>\u00a0and it has several issues:<\/p>\n<ol>\n<li>You need to handle\u00a0<code>KeyError<\/code>\u00a0exceptions.<\/li>\n<li>You need to convert types manually (see\u00a0<code>DATABASE_PORT<\/code>\u00a0usage).<\/li>\n<\/ol>\n<p>To fix\u00a0<code>KeyError<\/code>, you can write your own custom wrapper. For example:<br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/5f8ff261bcf8e0e2274cbb0b827eeedb.js\"><\/script><br \/>\n<!--n:-->Run the project\u2019s development server to check whether all the variables are set correctly.<!--.--><\/p>\n<p>Also, you can set default values for this wrapper and add type conversion. But actually there is no need to write this wrapper, because you can use a third-party library (we&#8217;ll talk about this\u00a0later).<\/p>\n<p><!--n:-->The <code>.env<\/code> file contains sensitive data, so you shouldn\u2019t upload it to a git repository. Instead, you must add the file to the list of <code>.gitignore<\/code> files for your Django project. There, you should keep all the files and directories you don\u2019t want to upload to git.<!--.--><\/p>\n<h4>Pros:<\/h4>\n<ul>\n<li>Django config is separated from code.<!--Configuration is separated from code.--><\/li>\n<li>Environment parity \u2013 you have the same code for all environments.<\/li>\n<li>No inheritance in settings, and cleaner and more consistent code.<\/li>\n<li>There is a theoretical grounding for using Django environment variables \u2013\u00a012 Factors.<\/li>\n<\/ul>\n<h4>Cons:<\/h4>\n<ul>\n<li>You need to handle sharing default config between developers.<\/li>\n<\/ul>\n<h2>12 Factors<\/h2>\n<p>12 Factors is a collection of recommendations on how to build distributed web-apps that will be easy to deploy and scale in the Cloud. It was created by\u00a0<a href=\"https:\/\/www.heroku.com\/\">Heroku<\/a>, a well-known Cloud hosting provider.<br \/>\nAs the name suggests, the collection consists of twelve parts:<\/p>\n<ol>\n<li>Codebase<\/li>\n<li>Dependencies<\/li>\n<li>Config<\/li>\n<li>Backing services<\/li>\n<li>Build, release, run<\/li>\n<li>Processes<\/li>\n<li>Port binding<\/li>\n<li>Concurrency<\/li>\n<li>Disposability<\/li>\n<li>Dev\/prod parity<\/li>\n<li>Logs<\/li>\n<li>Admin processes<\/li>\n<\/ol>\n<p>Each point describes a recommended way to implement a specific aspect of the project. Some of these points are covered by instruments like Django, Python, pip. Some are covered by design patterns or the infrastructure setup. In the context of this article, we are interested in one part: <a href=\"https:\/\/12factor.net\/config\">Configuration<\/a>.<\/p>\n<p>Its main rule is\u00a0<strong>to store configuration in the environment<\/strong>. Following this recommendation will give us strict separation of config from code.<br \/>\nYou can read more on\u00a0<a href=\"https:\/\/12factor.net\/\">12factor.net<\/a>.<\/p>\n<h2>django-environ<\/h2>\n<p>Based on the above, we see that\u00a0<strong>Django env variables are the perfect place to store settings<\/strong>.<br \/>\nNow it&#8217;s time to talk about the toolkit.<\/p>\n<p>Writing code using\u00a0<code>os.environ<\/code>\u00a0could be tricky sometimes and require additional effort to handle errors. It&#8217;s better to use\u00a0<a href=\"https:\/\/django-environ.readthedocs.io\/en\/latest\/\"><strong>django-environ<\/strong><\/a>\u00a0instead.<\/p>\n<p>Technically it&#8217;s a merge of:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/rconradharris\/envparse\" rel=\"nofollow\">envparse<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/nickstenning\/honcho\" rel=\"nofollow\">honcho<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/kennethreitz\/dj-database-url\" rel=\"nofollow\">dj-database-url<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/dstufft\/dj-search-url\" rel=\"nofollow\">dj-search-url<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/julianwachholz\/dj-config-url\" rel=\"nofollow\">dj-config-url<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/ghickman\/django-cache-url\" rel=\"nofollow\">django-cache-url<\/a><\/li>\n<\/ul>\n<p>This app gives a well-functioning API for reading values from environment variables or text files, handful type conversion, etc. Let&#8217;s look at some examples.<br \/>\nDjango <code>settings.py<\/code>\u00a0file before:<br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/897a963ec458b2f2bdfc7d79e6b9b43f.js\"><\/script><br \/>\nSettings.py in Django <!--Django <code>settings.py<\/code>\u00a0file -->after:<br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/8acdbe71c83aca23206f81c1cbb7dd03.js\"><\/script><br \/>\n<code>.env<\/code>\u00a0file:<br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/1ab194568218ee79cf5626f75205b844.js\"><\/script><\/p>\n<h2>Setting Structure<\/h2>\n<p>Instead of splitting settings by environments, you can split them by the source: Django, third- party apps (Celery, DRF, etc.), and your custom settings.<\/p>\n<p>File structure:<\/p>\n<pre><code>project\/\r\n\u251c\u2500\u2500 apps\/\r\n\u251c\u2500\u2500 settings\/\r\n\u2502   \u251c\u2500\u2500 __init__.py\r\n\u2502   \u251c\u2500\u2500 djano.py\r\n\u2502   \u251c\u2500\u2500 project.py\r\n\u2502   \u2514\u2500\u2500 third_party.py\r\n\u2514\u2500\u2500 manage.py\r\n<\/code><\/pre>\n<p><code>__init__.py<\/code>\u00a0file:<br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/9b6196bb642415871cf8d7de0ebc72cd.js\"><\/script><br \/>\nEach module could be done as a package, and you can split it more granularly:<\/p>\n<pre><code>project\/\r\n\u251c\u2500\u2500 apps\/\r\n\u251c\u2500\u2500 settings\/\r\n\u2502   \u251c\u2500\u2500 project\r\n\u2502   \u2502   \u251c\u2500\u2500 __init__.py\r\n\u2502   \u2502   \u251c\u2500\u2500 custom_module_foo.py\r\n\u2502   \u2502   \u251c\u2500\u2500 custom_module_bar.py\r\n\u2502   \u2502   \u2514\u2500\u2500 custom_module_xyz.py\r\n\u2502   \u251c\u2500\u2500 third_party\r\n\u2502   \u2502   \u251c\u2500\u2500 __init__.py\r\n\u2502   \u2502   \u251c\u2500\u2500 celery.py\r\n\u2502   \u2502   \u251c\u2500\u2500 email.py\r\n\u2502   \u2502   \u2514\u2500\u2500 rest_framework.py\r\n\u2502   \u251c\u2500\u2500 __init__.py\r\n\u2502   \u2514\u2500\u2500 djano.py\r\n\u2514\u2500\u2500 manage.py\r\n<\/code><\/pre>\n<h2>Naming Conventions<\/h2>\n<p>Naming of variables is one of the most complex parts of development. So is naming of settings. We can\u2019t imply on Django or third-party applications, but we can follow these simple rules for our custom (project) settings:<\/p>\n<ul>\n<li>Give meaningful names to your settings.<\/li>\n<li>Always use the prefix with the project name for your custom (project) settings.<\/li>\n<li>Write descriptions for your settings in comments.<\/li>\n<\/ul>\n<p><strong>Bad example:<\/strong><br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/d329d9de4079561bbcdb5e573c640262.js\"><\/script><br \/>\n<strong>Good example:<\/strong><br \/>\n<script src=\"https:\/\/gist.github.com\/alexryabtsev\/efd9f7337201664e6da6f38666f8e7ef.js\"><\/script><br \/>\nChange\u00a0<code>MYAWESOMEPROJECT<\/code>\u00a0to you real project name.<\/p>\n<h2>Django Settings: Best practices<\/h2>\n<p>Here are some of the Django production settings best practices:<!--\n\n\n<ul>\n \t\n\n<li>Keep settings in environment variables.<\/li>\n\n\n \t\n\n<li>Write default values for production configuration (excluding secret keys and tokens).<\/li>\n\n\n \t\n\n<li>Don't hardcode sensitive settings, and don't put them in VCS.<\/li>\n\n\n \t\n\n<li>Split settings into groups: Django, third-party, project.<\/li>\n\n\n \t\n\n<li>Follow naming conventions for custom (project) settings.<\/li>\n\n\n<\/ul>\n\n\n--><!--n:--><\/p>\n<ul>\n<li><b>Use a web server ready for production.<\/b> The best options for a Django application are Apache or Nginx. These servers can withstand high traffic and have better security systems than default Django servers.<\/li>\n<li><b>Apply PostgreSQL or MySQL databases.<\/b> These databases handle high traffic better than the default SQLite.<\/li>\n<li><b>Adopt Memcached or Redis cashing systems.<\/b> With their help, developers can speed up the response time for an app.<\/li>\n<li><b>Add HAProxy or NGINX load balancers<\/b> to share the load between servers. It will make an application more stable.<\/li>\n<li><b>Use Logstash, Elasticsearch, or Kibana logging systems.<\/b> They allow the configuration of an app for different environments and ensure the correct settings for each of them.<\/li>\n<li><b>Adopt Prometheus, Grafana, or Nagios monitoring systems.<\/b> These systems will help you detect and solve severe issues in time.<\/li>\n<li><b>Apply Docker.<\/b> A proper containerization technology helps package an application and its dependencies, allowing it to deploy and upscale an app quickly.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>The Settings file is a small but very important part of any Django project. If you do it wrong, you&#8217;ll have a lot of issues during all phases of development. But if you do it right, it will be a good basis for your project that will allow it to grow and scale in the future.<\/p>\n<p>Using the Django settings environment variables approach, <!--Using the environment variables approach, -->you can easily switch from a monolith to microservice architecture, wrap your project in Docker containers, and deploy it in any VPS or Cloud hosting platform such as: Amazon, Google Cloud, or your own Kubernetes cluster.<\/p>\n<p>Properly utilizing Django models methods can significantly enhance your application&#8217;s database interactions and data management.<\/p>\n<p>If you\u2019re comparing <a href=\"https:\/\/djangostars.com\/blog\/django-or-rails\/\">Django vs Ruby on rails<\/a> and need experienced developers for your project, contact the Django Stars team, <b>contact the Django Stars team<\/b>.<\/p>\n<h2>Sources:<\/h2>\n<ul>\n<li><a href=\"https:\/\/12factor.net\/\">https:\/\/12factor.net\/<\/a><\/li>\n<li><a href=\"https:\/\/django-environ.readthedocs.io\/en\/latest\/\">https:\/\/django-environ.readthedocs.io\/en\/latest\/<\/a><\/li>\n<\/ul>\n<div class=\"dj-main-article-faq\" style=\"padding-top: 0px;\">\n\t\t<div class=\"dj-main-article-faq-title\">\n\t\tFrequently Asked Questions\n\t\t<\/div>\n\t\t<div class=\"dj-main-article-faq-items\">\n\t\t\t<div class=\"dj-main-article-faq-accordeon accordeon\"><dl>\n\t\t\t\t<dt>What is the purpose of settings.py? \n\t\t\t\t<div class=\"cross\">\n\t\t\t\t<span><\/span>\n\t\t\t\t<span><\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<\/dt>\n\t\t\t\t<dd>The settings.py file is typically used to store configuration information in Django. It may contain the site URL, paths to various directories, and other values that the executable code may use. By changing and supplementing this file, the developers configure Django projects.<\/dd>\n\t\t\t<\/dl><dl>\n\t\t\t\t<dt>How to import Django settings \n\t\t\t\t<div class=\"cross\">\n\t\t\t\t<span><\/span>\n\t\t\t\t<span><\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<\/dt>\n\t\t\t\t<dd>There are various approaches for setting Django configurations. You can add <b>from .settings_local import *<\/b> to your settings.py file to import settings from settings_local.py. Also, you can make a settings package with different Python files to separate settings and specify for a project you run which Django configuration to use. And you can use environment variables.<\/dd>\n\t\t\t<\/dl><dl>\n\t\t\t\t<dt>How to use django-environ with several settings files? \n\t\t\t\t<div class=\"cross\">\n\t\t\t\t<span><\/span>\n\t\t\t\t<span><\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<\/dt>\n\t\t\t\t<dd>There's no proper solution for this. Either you need to duplicate setting definition in several files or you need to merge several files into one. (In most cases it happens for DEBUG setting, so just copy\/paste it.) Importing from another module can lead to circular cross imports, but it really depends on your project layout. <\/dd>\n\t\t\t<\/dl><dl>\n\t\t\t\t<dt>How to set environment variables in Django? \n\t\t\t\t<div class=\"cross\">\n\t\t\t\t<span><\/span>\n\t\t\t\t<span><\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<\/dt>\n\t\t\t\t<dd>To set environment variables, you can write code using <b>os.environ<\/b>. But it could be tricky sometimes and require additional effort to handle errors. Therefore, a convenient alternative is to use <b>django-environ<\/b>. This Python package gives a well-functioning API for reading values from environment variables or text files, handful type conversion, etc.<\/dd>\n\t\t\t<\/dl><dl>\n\t\t\t\t<dt>Which file has Django default configurations? \n\t\t\t\t<div class=\"cross\">\n\t\t\t\t<span><\/span>\n\t\t\t\t<span><\/span>\n\t\t\t\t<\/div>\n\t\t\t\t<\/dt>\n\t\t\t\t<dd>Typically, Django default configurations are stored in the settings.py file. However, there are other popular approaches, such as extending environment-specific settings in the settings_local.py file, splitting settings into different files for each environment, or storing settings in environment variables.<\/dd>\n\t\t\t<\/dl><\/div>\n\t\t\t<\/div>\n\t\t<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This article is intended for engineers who use the Django framework. It gives a deep insight and best practices into configuring Django project settings, and the pros and cons of different approaches. In the article, Django settings.py explained, you will also find recommendations concerning tools, best practices, and architectural solutions, all time-tested and proven by [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":3530,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[69,44],"tags":[30],"class_list":["post-942","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-django-engineering","category-python-django","tag-backend"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Software Development Blog &amp; IT Tech Insights | Django Stars<\/title>\n<meta name=\"description\" content=\"Master the art of Django settings configuration with our expert tips. Learn best practices to optimize your Django project for performance and security.\" \/>\n<link rel=\"canonical\" href=\"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts\/942\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Configuring Django Settings: Best Practices\" \/>\n<meta property=\"og:description\" content=\"Settings are what any project depends on \u2013 if you set them up right, get ready for smooth sailing. Learn the best practices for configuring Django project settings using time-tested tools and architectural solutions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/\" \/>\n<meta property=\"og:site_name\" content=\"Software Development Blog &amp; IT Tech Insights | Django Stars\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/djangostars\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/a.ryabtsev\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-08T10:39:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-12T12:35:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/djangostars.com\/blog\/uploads\/2019\/04\/cover-17.png\" \/>\n<meta name=\"author\" content=\"Alexander Ryabtsev\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Configuring Django Settings: Best Practices\" \/>\n<meta name=\"twitter:description\" content=\"Settings are what any project depends on \u2013 if you set them up right, get ready for smooth sailing. Learn the best practices for configuring Django project settings using time-tested tools and architectural solutions.\" \/>\n<meta name=\"twitter:creator\" content=\"@djangostars\" \/>\n<meta name=\"twitter:site\" content=\"@djangostars\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alexander Ryabtsev\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/\"},\"author\":{\"name\":\"Alexander Ryabtsev\",\"@id\":\"https:\/\/djangostars.com\/blog\/#\/schema\/person\/f1a566bbee334235e6f57edd6930fdc1\"},\"headline\":\"Configuring Django Settings: Best Practices\",\"datePublished\":\"2019-04-08T10:39:38+00:00\",\"dateModified\":\"2025-09-12T12:35:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/\"},\"wordCount\":1937,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/Configuring-Django-Settings_-Best-Practices.jpg\",\"keywords\":[\"Backend\"],\"articleSection\":[\"Django Engineering &amp; Dev Expertise for High-Load Projects\",\"Python &amp; Django\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/\",\"url\":\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/\",\"name\":\"Django Configurations: Best Practices of Settings | Django Stars\",\"isPartOf\":{\"@id\":\"https:\/\/djangostars.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/Configuring-Django-Settings_-Best-Practices.jpg\",\"datePublished\":\"2019-04-08T10:39:38+00:00\",\"dateModified\":\"2025-09-12T12:35:20+00:00\",\"author\":{\"@id\":\"https:\/\/djangostars.com\/blog\/#\/schema\/person\/f1a566bbee334235e6f57edd6930fdc1\"},\"description\":\"Master the art of Django settings configuration with our expert tips. Learn best practices to optimize your Django project for performance and security.\",\"breadcrumb\":{\"@id\":\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#primaryimage\",\"url\":\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/Configuring-Django-Settings_-Best-Practices.jpg\",\"contentUrl\":\"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/Configuring-Django-Settings_-Best-Practices.jpg\",\"width\":1440,\"height\":620},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/djangostars.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Configuring Django Settings: Best Practices\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/djangostars.com\/blog\/#website\",\"url\":\"https:\/\/djangostars.com\/blog\/\",\"name\":\"Software Development Blog &amp; IT Tech Insights | Django Stars\",\"description\":\"Welcome behind the scenes of software product development. We share our best practices, tech solutions, management tips, and every useful insight we\u2018ve got while working on our projects.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/djangostars.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/djangostars.com\/blog\/#\/schema\/person\/f1a566bbee334235e6f57edd6930fdc1\",\"name\":\"Alexander Ryabtsev\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/djangostars.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c456852d26226ecd8bc156a7339fc1f425a6774e8f9e07a977c060e2ecedebb9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c456852d26226ecd8bc156a7339fc1f425a6774e8f9e07a977c060e2ecedebb9?s=96&d=mm&r=g\",\"caption\":\"Alexander Ryabtsev\"},\"sameAs\":[\"https:\/\/www.facebook.com\/a.ryabtsev\",\"https:\/\/www.linkedin.com\/in\/alexander-ryabtsev\/\"],\"url\":\"https:\/\/djangostars.com\/blog\/author\/alexander-ryabtsev\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Software Development Blog &amp; IT Tech Insights | Django Stars","description":"Master the art of Django settings configuration with our expert tips. Learn best practices to optimize your Django project for performance and security.","canonical":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts\/942","og_locale":"en_US","og_type":"article","og_title":"Configuring Django Settings: Best Practices","og_description":"Settings are what any project depends on \u2013 if you set them up right, get ready for smooth sailing. Learn the best practices for configuring Django project settings using time-tested tools and architectural solutions.","og_url":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/","og_site_name":"Software Development Blog &amp; IT Tech Insights | Django Stars","article_publisher":"https:\/\/www.facebook.com\/djangostars\/","article_author":"https:\/\/www.facebook.com\/a.ryabtsev","article_published_time":"2019-04-08T10:39:38+00:00","article_modified_time":"2025-09-12T12:35:20+00:00","og_image":[{"url":"https:\/\/djangostars.com\/blog\/uploads\/2019\/04\/cover-17.png","type":"","width":"","height":""}],"author":"Alexander Ryabtsev","twitter_card":"summary_large_image","twitter_title":"Configuring Django Settings: Best Practices","twitter_description":"Settings are what any project depends on \u2013 if you set them up right, get ready for smooth sailing. Learn the best practices for configuring Django project settings using time-tested tools and architectural solutions.","twitter_creator":"@djangostars","twitter_site":"@djangostars","twitter_misc":{"Written by":"Alexander Ryabtsev","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#article","isPartOf":{"@id":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/"},"author":{"name":"Alexander Ryabtsev","@id":"https:\/\/djangostars.com\/blog\/#\/schema\/person\/f1a566bbee334235e6f57edd6930fdc1"},"headline":"Configuring Django Settings: Best Practices","datePublished":"2019-04-08T10:39:38+00:00","dateModified":"2025-09-12T12:35:20+00:00","mainEntityOfPage":{"@id":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/"},"wordCount":1937,"commentCount":0,"image":{"@id":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#primaryimage"},"thumbnailUrl":"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/Configuring-Django-Settings_-Best-Practices.jpg","keywords":["Backend"],"articleSection":["Django Engineering &amp; Dev Expertise for High-Load Projects","Python &amp; Django"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/","url":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/","name":"Django Configurations: Best Practices of Settings | Django Stars","isPartOf":{"@id":"https:\/\/djangostars.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#primaryimage"},"image":{"@id":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#primaryimage"},"thumbnailUrl":"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/Configuring-Django-Settings_-Best-Practices.jpg","datePublished":"2019-04-08T10:39:38+00:00","dateModified":"2025-09-12T12:35:20+00:00","author":{"@id":"https:\/\/djangostars.com\/blog\/#\/schema\/person\/f1a566bbee334235e6f57edd6930fdc1"},"description":"Master the art of Django settings configuration with our expert tips. Learn best practices to optimize your Django project for performance and security.","breadcrumb":{"@id":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#primaryimage","url":"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/Configuring-Django-Settings_-Best-Practices.jpg","contentUrl":"https:\/\/djangostars.com\/blog\/wp-content\/uploads\/2021\/12\/Configuring-Django-Settings_-Best-Practices.jpg","width":1440,"height":620},{"@type":"BreadcrumbList","@id":"https:\/\/djangostars.com\/blog\/configuring-django-settings-best-practices\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/djangostars.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Configuring Django Settings: Best Practices"}]},{"@type":"WebSite","@id":"https:\/\/djangostars.com\/blog\/#website","url":"https:\/\/djangostars.com\/blog\/","name":"Software Development Blog &amp; IT Tech Insights | Django Stars","description":"Welcome behind the scenes of software product development. We share our best practices, tech solutions, management tips, and every useful insight we\u2018ve got while working on our projects.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/djangostars.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/djangostars.com\/blog\/#\/schema\/person\/f1a566bbee334235e6f57edd6930fdc1","name":"Alexander Ryabtsev","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/djangostars.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c456852d26226ecd8bc156a7339fc1f425a6774e8f9e07a977c060e2ecedebb9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c456852d26226ecd8bc156a7339fc1f425a6774e8f9e07a977c060e2ecedebb9?s=96&d=mm&r=g","caption":"Alexander Ryabtsev"},"sameAs":["https:\/\/www.facebook.com\/a.ryabtsev","https:\/\/www.linkedin.com\/in\/alexander-ryabtsev\/"],"url":"https:\/\/djangostars.com\/blog\/author\/alexander-ryabtsev\/"}]}},"_links":{"self":[{"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts\/942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/comments?post=942"}],"version-history":[{"count":26,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts\/942\/revisions"}],"predecessor-version":[{"id":9687,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/posts\/942\/revisions\/9687"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/media\/3530"}],"wp:attachment":[{"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/media?parent=942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/categories?post=942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/djangostars.com\/blog\/wp-json\/wp\/v2\/tags?post=942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}