{"id":312,"date":"2023-05-03T17:14:02","date_gmt":"2023-05-03T11:14:02","guid":{"rendered":"http:\/\/itllive.com\/knowledgebase\/?p=312"},"modified":"2023-05-03T17:23:49","modified_gmt":"2023-05-03T11:23:49","slug":"django-environment-setup-basics","status":"publish","type":"post","link":"https:\/\/itllive.com\/knowledgebase\/2023\/05\/03\/django-environment-setup-basics\/","title":{"rendered":"Django Environment Setup Basics"},"content":{"rendered":"<p><strong>Download &amp; Install Python:<\/strong><\/p>\n<p>Download and install the latest Python version for Windows from https:\/\/www.python.org\/downloads.<\/p>\n<p>Open Command Prompt and run following command to check if Python was installed properly.<br \/>\n<code>&gt; python --version<\/code><\/p>\n<p>It will show the version information if working properly.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Install PIP:<\/strong><\/p>\n<p>PIP is a package manager for Python packages, or modules. If you have Python version 3.4 or later, PIP is included by default. Check PIP version with the following command.<br \/>\n<code>&gt; pip --version<\/code><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Install IDE (VS Code):<\/strong><\/p>\n<p>Download &amp; install VS Code from Microsoft and install <strong>Python<\/strong> extension by Microsoft in it.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Project Directory Setup:<\/strong><\/p>\n<p>Create a directory named PYTHON in a drive other than C. Literally this is an optional setup but helps organize your job.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Create a Directory for your Django Project:<\/strong><\/p>\n<p>Navigate to PYTHON directory from Command Prompt and run the following command to create a directory for your new Django project.<br \/>\n<code>&gt; cd D:\\PYTHON<br \/>\n&gt; D:\\PYTHON&gt; mkdir helloworld<br \/>\n&gt; D:\\PYTHON&gt; cd helloworld<br \/>\n&gt; D:\\PYTHON\\helloworld&gt;<\/code><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Install Virtual Environment:<\/strong><\/p>\n<p>Install virtual environment for django in your project. Here .venv will be your virtual environment directory which you will be calling later.<br \/>\n<code>&gt; python -m venv .venv<\/code><br \/>\nNow activate the virtual environment with below command.<br \/>\n<code>&gt; .venv\\Scripts\\Activate.ps1<\/code><br \/>\nIf activated, you will see something like below.<br \/>\n<code>(.venv) PS D:\\PYTHON\\helloworld&gt;<\/code><br \/>\n<strong>Install Django:<\/strong><\/p>\n<p>Run the following command to install Django in your project helloworld.<br \/>\n<code>(.venv) PS D:\\PYTHON\\helloworld&gt; pip install Django<\/code><br \/>\n<strong>Create a Django Project:<\/strong><br \/>\n<code>(.venv) PS D:\\PYTHON\\helloworld&gt; django-admin startproject helloworldproject .<\/code><\/p>\n<p>Here the ending dot (.) is particularly important because without that, django will create another helloworldproject directory inside the original helloworldproject directory.<\/p>\n<p>Well, at this stage you will be able to find the following files created inside the helloworldproject directory.<\/p>\n<pre><code>helloworld\/\r\n\u2502   \u251c\u2500\u2500 helloworldproject\/\r\n\u2502   \u2502   \u251c\u2500\u2500 __init__.py\r\n\u2502   \u2502   \u251c\u2500\u2500 settings.py\r\n\u2502   \u2502   \u251c\u2500\u2500 urls.py\r\n\u2502   \u2502   \u2514\u2500\u2500 wsgi.py\r\n\u2502   \u2502\r\n\u2502   \u2514\u2500\u2500 manage.py\r\n\u2502\r\n\u2514\u2500\u2500 .venv\/\r\n\r\n<\/code><\/pre>\n<p><strong>Start the Development Server:<\/strong><\/p>\n<p>Once your file structure is set up, you can now start the server and check that your set up was successful. In the console, run the following command:<\/p>\n<pre><code>&gt; python manage.py runserver<\/code><\/pre>\n<p>Then, in your browser go to localhost:8000, and you should see the following:<\/p>\n<p><a href=\"http:\/\/itllive.com\/knowledgebase\/2023\/05\/03\/django-environment-setup-basics\/python_app_landing_page\/\" rel=\"attachment wp-att-316\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-316\" src=\"http:\/\/itllive.com\/knowledgebase\/wp-content\/uploads\/2023\/05\/python_app_landing_page.webp\" alt=\"\" width=\"777\" height=\"533\" srcset=\"https:\/\/itllive.com\/knowledgebase\/wp-content\/uploads\/2023\/05\/python_app_landing_page.webp 777w, https:\/\/itllive.com\/knowledgebase\/wp-content\/uploads\/2023\/05\/python_app_landing_page-300x206.webp 300w, https:\/\/itllive.com\/knowledgebase\/wp-content\/uploads\/2023\/05\/python_app_landing_page-768x527.webp 768w\" sizes=\"auto, (max-width: 777px) 100vw, 777px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Download &amp; Install Python: Download and install the latest Python version for Windows from https:\/\/www.python.org\/downloads. Open Command Prompt ...<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[],"class_list":["post-312","post","type-post","status-publish","format-standard","hentry","category-django"],"_links":{"self":[{"href":"https:\/\/itllive.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itllive.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itllive.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itllive.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itllive.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=312"}],"version-history":[{"count":7,"href":"https:\/\/itllive.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/312\/revisions"}],"predecessor-version":[{"id":320,"href":"https:\/\/itllive.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/312\/revisions\/320"}],"wp:attachment":[{"href":"https:\/\/itllive.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itllive.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itllive.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}