{"id":120189,"date":"2024-12-17T03:36:35","date_gmt":"2024-12-17T03:36:35","guid":{"rendered":"\/tutorials\/?p=120189"},"modified":"2024-12-20T09:56:21","modified_gmt":"2024-12-20T09:56:21","slug":"how-to-create-a-django-project","status":"publish","type":"post","link":"\/in\/tutorials\/how-to-create-a-django-project\/","title":{"rendered":"How to create a Django project"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Creating a Django project is the first step in harnessing the power of this popular web framework. Known for its &#8220;batteries-included&#8221; philosophy, Django provides developers with a comprehensive set of tools for tasks like user authentication, content administration, and database management.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This combination of features makes Django a favorite for building dynamic, data-driven websites and applications. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this tutorial, we\u2019ll guide you through the process of setting up and creating your first Django project. Let\u2019s get started!<\/p>\n\n\n\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-prerequisites\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before you start creating your Django project, you\u2019ll need a VPS for your projects. Hostinger\u2019s <a data-click-id=\"hgr-post-content-link-django-vps-hosting\" href=\"\/in\/vps\/django-hosting\">Django VPS hosting<\/a> provides an environment specifically tailored to getting your Django projects up and running quickly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The most popular plan comes with <strong>2 vCPU<\/strong> cores, <strong>8 GB<\/strong> RAM, and <strong>100 GB <\/strong>of NVMe SSD storage, which is suitable for up to a medium-scale Django project.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After purchasing a server to host your project, <a data-click-id=\"hgr-post-content-link-install-django\" href=\"\/in\/tutorials\/how-to-install-django\/\">install Django<\/a> since we will use its command to set up the project directory. If you use Hostinger\u2019s VPS, you can easily set up the framework by choosing the Django template during the onboarding process.<\/p>\n\n\n<figure class=\"wp-block-image size-large\"><a data-click-id=\"hgr-post-content-link-in-vps-hosting\" aria-label=\"Vps hosting\" href=\"\/in\/vps-hosting\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Also set up a <a data-click-id=\"hgr-post-content-link-python-virtual-environment\" href=\"\/in\/tutorials\/how-to-create-a-python-virtual-environment\/\">Python virtual environment<\/a> to isolate your application data from other projects and services in your system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-creating-a-new-django-project\">Creating a new Django project<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s time to create your first Django app. In this section, you will establish the codebase foundation needed to begin developing your project.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding, connect to your server via <a data-click-id=\"hgr-post-content-link-ssh-using-putty\" href=\"\/in\/tutorials\/how-to-use-putty-ssh\/\">SSH using PuTTY<\/a> or Terminal. For Hostinger users, you can access your VPS in one click using <strong>Browser terminal<\/strong> by simply clicking the button on your VPS management page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once connected, let\u2019s create a new Django project:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to your project directory. If you&#8217;re not already in the directory where you want to create the project, use the <strong>cd <\/strong>command to navigate there.<\/li>\n\n\n\n<li>Use Django&#8217;s <strong>startproject <\/strong>command to create a new project. Replace <strong>myproject<\/strong> with the name of your project:<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">django-admin startproject myproject<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The above command would create a new directory named <strong>myproject <\/strong>containing the default project structure.<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Then, navigate to your project&#8217;s inner folder:<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd myproject\/myproject<\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li>Open <strong>settings.py<\/strong> using one of the default Ubuntu text editors (<strong>nano<\/strong> or <strong>vim<\/strong>):<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vim settings.py<\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li>Locate the <strong>ALLOWED_HOSTS<\/strong> setting and add your VPS IP as follows. This configuration ensures your server can access and serve the Django project:<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ALLOWED_HOSTS = ['your_vps_ip']<\/pre>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li>Save the changes and quit vim by entering <strong>:wq<\/strong>.<\/li>\n\n\n\n<li>To verify that everything is set up correctly, you can start the Django development server. Return to the parent project category and enter <strong>runserver<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd ..<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python manage.py runserver 0.0.0.0:8000<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now, open your browser and go to <strong>http:\/\/your_vps_ip:8000\/ <\/strong>with <strong>your_vps_ip<\/strong> being your actual VPS IP. If the setting was correct, you should see the Django welcome page:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6b0b4b1b9563e&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6b0b4b1b9563e\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"521\" height=\"355\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/install_django_2.png\/public\" alt=\"Screenshot displaying default Django web page, containing text &quot;The install worked successfully! Congratulations!&quot; as well as a rocket launching above the text and version information below.\" class=\"wp-image-116657\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/install_django_2.png\/w=521,fit=scale-down 521w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/install_django_2.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/install_django_2.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 521px) 100vw, 521px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">If you followed through with these steps, you successfully built and executed a default Django project on your VPS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading h-t-title-3\" id=\"h-understanding-the-django-project-structure\">Understanding the Django project structure<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Running the <strong>startproject <\/strong>command creates a basic Django project structure that includes several key files and directories. Each of them plays a specific role in your Django project. Here\u2019s a breakdown of the structure and the purpose of each component:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6b0b4b1b97584&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6b0b4b1b97584\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"257\" height=\"219\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_1.png\/public\" alt=\"Screenshot displaying default Django project structure: db.sqlite3 and manage.py files in the main myproject directory and init.py, asgi.py, settings.py, urls.py, wsgi.py files and pycache category inside the inner myproject directory\" class=\"wp-image-116659\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_1.png\/w=257,fit=scale-down 257w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_1.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 257px) 100vw, 257px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>myproject\/<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The inner project directory containing the core settings, configurations, and other default files for your Django project.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>manage.py<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This command-line utility lets you interact with your Django project. You use it for tasks such as running the development server, migrating databases, and managing your application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s what it looks like:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6b0b4b1b9976a&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6b0b4b1b9976a\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"678\" height=\"442\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_2.png\/public\" alt=\"Screenshot of the default manage.py file opened in VS code editor\" class=\"wp-image-116662\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_2.png\/w=678,fit=scale-down 678w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_2.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_2.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 678px) 100vw, 678px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">These are its key functions:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6b0b4b1b9ba8e&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6b0b4b1b9ba8e\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"590\" height=\"22\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_3.png\/public\" alt=\"Screenshot of text &quot;os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')\" class=\"wp-image-116665\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_3.png\/w=590,fit=scale-down 590w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_3.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_3.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 590px) 100vw, 590px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Sets the environment variable to tell Django which settings file to use.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6b0b4b1b9db62&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6b0b4b1b9db62\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"301\" height=\"18\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_4.png\/public\" alt=\"Screenshot of text &quot;execute_from_command_line(sys.argv)&quot;\" class=\"wp-image-116666\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_4.png\/w=301,fit=scale-down 301w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_4.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 301px) 100vw, 301px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Runs various Django commands such as <strong>runserver<\/strong>, <strong>migrate<\/strong>, and others.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>__init__.py<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This file converts your project directory as a Python package, allowing Python to import your project code as a module. It\u2019s empty by default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>settings.py<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is one of the most crucial files in Django. It contains all the settings for your project, including database configurations, installed apps, middleware, and static file settings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>urls.py<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This file defines the URL routes for your application. It maps URLs to <a data-click-id=\"hgr-post-content-link-views\" href=\"\/in\/tutorials\/building-django-views\/\">views<\/a> that process requests and return responses.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6b0b4b1ba00d5&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6b0b4b1ba00d5\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"365\" height=\"135\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_5.png\/public\" alt=\"Screenshot of a default url.py file structure\" class=\"wp-image-116667\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_5.png\/w=365,fit=scale-down 365w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_5.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_5.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 365px) 100vw, 365px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">As you add more functionality to your application, you&#8217;ll extend <strong>urlpatterns<\/strong> to include routes for your own views.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>asgi.py<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This file provides an entry point for ASGI-compatible web servers to serve your project. ASGI (Asynchronous Server Gateway Interface) is the standard for asynchronous Django applications.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6b0b4b1ba214c&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6b0b4b1ba214c\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"645\" height=\"154\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_6.png\/public\" alt=\"Screenshot of a default asgi.py file structure\" class=\"wp-image-116669\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_6.png\/w=645,fit=scale-down 645w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_6.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_6.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 645px) 100vw, 645px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>wsgi.py<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This file is the entry point for WSGI-compatible web servers such as Gunicorn or uWSGI to serve your project in a production environment.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6b0b4b1ba45a9&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6b0b4b1ba45a9\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"647\" height=\"152\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_7.png\/public\" alt=\"Screenshot of a default wsgi.py file structure\" class=\"wp-image-116670\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_7.png\/w=647,fit=scale-down 647w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_7.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/52\/2024\/09\/understanding_the_project_structure_7.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 647px) 100vw, 647px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Understanding the role of each file and directory will equip you to modify settings, add URLs, and manage your project\u2019s structure.<\/p>\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To begin working with Django you\u2019ll first need to learn how to create a project. The process is really not that complicated and can be done in a few steps.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before doing so, however, make sure you have a server with sufficient hardware according to your project\u2019s need. Also, your system should have Django installed and environment variable set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To summarize, go to your projects directory and use the <strong>startproject <\/strong>command to create a new project. Navigate to your project\u2019s inner folder and add your server&#8217;s IP to <strong>ALLOWED_HOSTS<\/strong>. If all is done correctly, your new blank project should be up and running.<\/p>\n\n\n\n<h2 class=\"wp-block-heading h-t-title-2\" id=\"h-how-to-create-django-project-faq\">How to create Django project FAQ<\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1734409263471\"><h3 class=\"schema-faq-question\">How do I configure settings in a Django project?<\/h3> <p class=\"schema-faq-answer\">To configure your Django project settings, open the <strong>settings.py<\/strong> file inside your project directory. Here, you can change various configurations by adjusting the value of each parameter. For example, you can toggle the debug mode or list known hosts.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1734409264499\"><h3 class=\"schema-faq-question\">How do I run the Django development server?<\/h3> <p class=\"schema-faq-answer\">To run the Django development server, open your system\u2019s terminal and navigate to your project folder, which contains the<strong> manage.py<\/strong> file. Activate your virtual environment if you use one. Then, enter <strong>python manage.py runserver<\/strong> to start the development server using<strong> <\/strong>via port <strong>8000<\/strong>.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Creating a Django project is the first step in harnessing the power of this popular web framework. Known for its &#8220;batteries-included&#8221; philosophy, Django provides developers with a comprehensive set of tools for tasks like user authentication, content administration, and database management. This combination of features makes Django a favorite for building dynamic, data-driven websites and [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/in\/tutorials\/how-to-create-a-django-project\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":185,"featured_media":120144,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"","rank_math_description":"","rank_math_focus_keyword":"","_content_updated_date":"","footnotes":""},"categories":[22702,22664],"tags":[],"class_list":["post-120189","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pre-installed-applications","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-create-a-django-project\/","default":1},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-create-a-django-project\/","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-create-a-django-project\/","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-create-a-django-project\/","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-create-a-django-project\/","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-create-a-django-project\/","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-create-a-django-project\/","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-create-a-django-project\/","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/120189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/users\/185"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/comments?post=120189"}],"version-history":[{"count":8,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/120189\/revisions"}],"predecessor-version":[{"id":120593,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/120189\/revisions\/120593"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media\/120144"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media?parent=120189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/categories?post=120189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/tags?post=120189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}