{"id":165,"date":"2026-03-03T09:32:27","date_gmt":"2026-03-03T04:32:27","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=165"},"modified":"2026-03-17T09:08:12","modified_gmt":"2026-03-17T04:08:12","slug":"deploying-django-project","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/deploying-django-project\/","title":{"rendered":"Deploying Django Project"},"content":{"rendered":"\n<p>Deploying a Django project means making your web application live on the internet so users can access it.<\/p>\n\n\n\n<p>After building your project locally, deployment allows it to run on a production server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Development vs Production<\/h2>\n\n\n\n<p>Development:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Runs on local machine<\/li>\n\n\n\n<li>Uses built-in Django server<\/li>\n\n\n\n<li>Used for testing<\/li>\n<\/ul>\n\n\n\n<p>Production:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Hosted on a live server<\/li>\n\n\n\n<li>Uses production web server<\/li>\n\n\n\n<li>Accessible worldwide<\/li>\n<\/ul>\n\n\n\n<p>You should never use <code>runserver<\/code> for production.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Prepare Your Project for Deployment<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Set DEBUG to False<\/h3>\n\n\n\n<p>In <code>settings.py<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">DEBUG = False<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Add Allowed Hosts<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">ALLOWED_HOSTS = ['yourdomain.com', 'www.yourdomain.com']<\/pre>\n\n\n\n<p>This prevents security issues.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Configure Static Files<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')<\/pre>\n\n\n\n<p>Then collect static files:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">python manage.py collectstatic<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Choose a Hosting Platform<\/h2>\n\n\n\n<p>Popular platforms for deploying Django:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Heroku<\/li>\n\n\n\n<li>PythonAnywhere<\/li>\n\n\n\n<li>DigitalOcean<\/li>\n\n\n\n<li>AWS (Amazon Web Services)<\/li>\n\n\n\n<li>Render<\/li>\n\n\n\n<li>VPS Hosting<\/li>\n<\/ul>\n\n\n\n<p>Choose based on budget and project size.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Use Production Server (Gunicorn)<\/h2>\n\n\n\n<p>Install Gunicorn:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pip install gunicorn<\/pre>\n\n\n\n<p>Run project using Gunicorn:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">gunicorn myproject.wsgi<\/pre>\n\n\n\n<p>Gunicorn acts as a production web server for Django.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Use Nginx (Optional but Recommended)<\/h2>\n\n\n\n<p>Nginx is used to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Handle static files<\/li>\n\n\n\n<li>Manage traffic<\/li>\n\n\n\n<li>Improve performance<\/li>\n\n\n\n<li>Add security<\/li>\n<\/ul>\n\n\n\n<p>Production architecture:<\/p>\n\n\n\n<p>User \u2192 Nginx \u2192 Gunicorn \u2192 Django \u2192 Database<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Configure Database<\/h2>\n\n\n\n<p>In production, use:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PostgreSQL (recommended)<\/li>\n\n\n\n<li>MySQL<\/li>\n<\/ul>\n\n\n\n<p>Avoid using SQLite for large production systems.<\/p>\n\n\n\n<p>Example PostgreSQL configuration:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">DATABASES = {<br>    'default': {<br>        'ENGINE': 'django.db.backends.postgresql',<br>        'NAME': 'dbname',<br>        'USER': 'dbuser',<br>        'PASSWORD': 'password',<br>        'HOST': 'localhost',<br>        'PORT': '5432',<br>    }<br>}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Environment Variables<\/h2>\n\n\n\n<p>Do not hard-code sensitive data.<\/p>\n\n\n\n<p>Use environment variables for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SECRET_KEY<\/li>\n\n\n\n<li>Database credentials<\/li>\n\n\n\n<li>API keys<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import os<br>SECRET_KEY = os.environ.get('SECRET_KEY')<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 7: Migrate Database on Server<\/h2>\n\n\n\n<p>After deployment:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">python manage.py migrate<\/pre>\n\n\n\n<p>Create superuser:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">python manage.py createsuperuser<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 8: Enable HTTPS<\/h2>\n\n\n\n<p>Use SSL certificate for secure connection.<\/p>\n\n\n\n<p>HTTPS:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Encrypts data<\/li>\n\n\n\n<li>Protects users<\/li>\n\n\n\n<li>Required for production apps<\/li>\n<\/ul>\n\n\n\n<p>Let\u2019s Encrypt provides free SSL certificates.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Deployment Files<\/h2>\n\n\n\n<p>requirements.txt \u2192 List of project dependencies<br>Procfile \u2192 Used in Heroku<br>.env \u2192 Environment variables file<\/p>\n\n\n\n<p>Create requirements file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pip freeze &gt; requirements.txt<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Deployment Checklist<\/h2>\n\n\n\n<p>Set DEBUG = False<br>Add ALLOWED_HOSTS<br>Configure database<br>Configure static files<br>Use Gunicorn<br>Use Nginx<br>Use environment variables<br>Enable HTTPS<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Deployment Knowledge is Important<\/h2>\n\n\n\n<p>Deployment helps you:<\/p>\n\n\n\n<p>Launch real-world applications<br>Share projects with clients<br>Build production-ready systems<br>Understand server management<br>Work as a professional developer<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Key Takeaway<\/h2>\n\n\n\n<p>Deploying a Django project involves configuring production settings, choosing a hosting platform, setting up a production server like Gunicorn, managing static files, securing data, and connecting a production database.<\/p>\n\n\n\n<p>Proper deployment ensures your application is secure, scalable, and accessible to users worldwide.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/python\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">PYTHON FOR WEB DEVELOPMENT (PYWEB) > REST API Development > Deploying Django Project<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773720485159\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p><\/p>\n","protected":false},"menu_order":92,"template":"","class_list":["post-165","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Deploying Django Project - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Step-by-step guide to deploy Django projects with Gunicorn, Nginx, PostgreSQL, and HTTPS for secure, production-ready apps.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/python\/lesson\/deploying-django-project\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deploying Django Project - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Step-by-step guide to deploy Django projects with Gunicorn, Nginx, PostgreSQL, and HTTPS for secure, production-ready apps.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/deploying-django-project\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-17T04:08:12+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/deploying-django-project\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/deploying-django-project\\\/\",\"name\":\"Deploying Django Project - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-03-03T04:32:27+00:00\",\"dateModified\":\"2026-03-17T04:08:12+00:00\",\"description\":\"Step-by-step guide to deploy Django projects with Gunicorn, Nginx, PostgreSQL, and HTTPS for secure, production-ready apps.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/deploying-django-project\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/deploying-django-project\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/deploying-django-project\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PYTHON FOR WEB DEVELOPMENT (PYWEB) > REST API Development > Deploying Django Project\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\",\"name\":\"One Language. Endless Possibilities\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deploying Django Project - One Language. Endless Possibilities","description":"Step-by-step guide to deploy Django projects with Gunicorn, Nginx, PostgreSQL, and HTTPS for secure, production-ready apps.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/python\/lesson\/deploying-django-project\/","og_locale":"en_US","og_type":"article","og_title":"Deploying Django Project - One Language. Endless Possibilities","og_description":"Step-by-step guide to deploy Django projects with Gunicorn, Nginx, PostgreSQL, and HTTPS for secure, production-ready apps.","og_url":"https:\/\/gigz.pk\/python\/lesson\/deploying-django-project\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-17T04:08:12+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/python\/lesson\/deploying-django-project\/","url":"https:\/\/gigz.pk\/python\/lesson\/deploying-django-project\/","name":"Deploying Django Project - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-03-03T04:32:27+00:00","dateModified":"2026-03-17T04:08:12+00:00","description":"Step-by-step guide to deploy Django projects with Gunicorn, Nginx, PostgreSQL, and HTTPS for secure, production-ready apps.","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/deploying-django-project\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/deploying-django-project\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/deploying-django-project\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"PYTHON FOR WEB DEVELOPMENT (PYWEB) > REST API Development > Deploying Django Project"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/python\/#website","url":"https:\/\/gigz.pk\/python\/","name":"One Language. Endless Possibilities","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson\/165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/media?parent=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}