{"id":83187,"date":"2021-08-17T09:00:04","date_gmt":"2021-08-17T03:30:04","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=83187"},"modified":"2021-08-17T09:00:04","modified_gmt":"2021-08-17T03:30:04","slug":"create-your-first-django-app","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/","title":{"rendered":"How to Create Your First Django App in 5 Easy Steps"},"content":{"rendered":"<p>In this tutorial, we will learn how to create, install and deploy our first Django app effortlessly. We will be working with some of the app and project files. We will learn the basics of how these files interact among themselves and finally create our first web page.<\/p>\n<p>Let\u2019s dive into the steps for creating a Django app.<\/p>\n<h3>How to Create Your First Django App?<\/h3>\n<p>Django provides the feature of code reusability, which enables the users to migrate the pre-built apps in their project and also customize their web applications.<\/p>\n<p>Before we begin creating our first app just execute this command inside the project directory.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">python manage.py makemigrations<\/pre>\n<p>Once you are completed with the above command execute this command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">python manage.py migrate<\/pre>\n<h3>Steps to Create the Django Applications<\/h3>\n<p><strong>Step 1: Open your Command Prompt or Window PowerShell.<\/strong><\/p>\n<p>Move to the directory where you have made the setup for the Virtual environment.<\/p>\n<p>Activate your Virtual environment by typing the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">(virtual-environment-name)\\Scripts\\activate.bat\n<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/step-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83857\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/step-1.png\" alt=\"Create Django App\" width=\"1907\" height=\"287\" \/><\/a><\/p>\n<p>Your virtual environment is activated.<\/p>\n<p>Change the directory to your project folder. Here it is named \u201cTechVidvan\u201d.<\/p>\n<p><strong>Step 2: Initialising the Django Application<\/strong><\/p>\n<p>Type the following command in the Command prompt:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Django-admin startapp application-name<\/pre>\n<p>The command execution is shown below:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/step-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83858\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/step-2.png\" alt=\"Django App Creation\" width=\"1865\" height=\"707\" \/><\/a><\/p>\n<p>So, in our root directory, we have a new directory named HelloWorld( application-name). This directory contains all the files that our application will need and we will modify them accordingly to accomplish our desired goals.<\/p>\n<ul>\n<li>Name your application suitably, according to the task it performs.<\/li>\n<li>Create an application only when the task it performs can not be fulfilled by any other existing applications. That means avoid redundancy.<\/li>\n<\/ul>\n<p>Following the above-mentioned tips will help you to build your projects easily. You can be very specific about which app you want to add to your project and the one that you should avoid. This will increase your development speed and decrease your workload.<\/p>\n<p>The app comes with some pre-installed files which are as follows:<\/p>\n<ul>\n<li>migrations<\/li>\n<li>admin.py<\/li>\n<li>apps.py<\/li>\n<li>models.py<\/li>\n<li>tests.py<\/li>\n<li>views.py<\/li>\n<li>_init_.py<\/li>\n<\/ul>\n<p><strong>Step 3: Installing Django App<\/strong><\/p>\n<p>The app we have just created \u201dHelloWorld\u201d( App name) is in the same project folder \u201cTechVidvan\u201d( Project name), but we need to install the application.<\/p>\n<p>Switch on the Visual Studio code. Move to the settings.py file of the project. Remember, we are working on the setting.py file of our project, not the one under the app directory.<\/p>\n<p>We have to just type the name of our application under the INSTALLED_APPS. Remember to put a comma after the app name.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/step-3-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83859\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/step-3-1.png\" alt=\"Installing Django App\" width=\"1920\" height=\"1028\" \/><\/a><\/p>\n<p><strong>Step 4: Adding App in urls.py File<\/strong><\/p>\n<p>The reason to add the app to our urls.py file is that, if anyone will search the URL of the app it will display this app.<\/p>\n<p>We will first work with our app. We need to create a new python file in our HelloWorld directory( App directory). To do so, click on the new file logo, just above your app name. This will open a search bar. Write urls.py in it and it will create a new file under your app directory.<\/p>\n<p>Just paste the following command in your newly created urls.py file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from django.urls import path\nfrom.import views\nurlpatterns = [\npath('', views.index, name='index'),\n]\n<\/pre>\n<p>This code is directing our Django project to initiate this function in the views.py file. We will make changes in views.py too.<\/p>\n<p>We have imported both the django.urls package and path function from views.py file.<\/p>\n<p>Here we have passed two arguments in the path function. The first is the URL that was searched, the second argument is to execute the file which is the index file in our case.<\/p>\n<p>The next step is to modify the urls.py file of our project.<\/p>\n<p>Paste the following code in your urls.py file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from django.contrib import admin\nfrom django.urls import include, path\nurlpatterns = [\npath('HelloWorld\/', include('HelloWorld.urls')),\npath('admin\/', admin.site.urls),\n]<\/pre>\n<p>This tells the system to direct the server to check the URL for the HelloWorld keyword. This will again direct the URL to the urls.py file inside the HelloWorld app directory.<\/p>\n<p><strong>Step 5: Constructing the Views.py file<\/strong><\/p>\n<p>Views.py is responsible for displaying the text on our web application.<\/p>\n<p>Paste the following code in the views.py file under the HelloWorld directory( app directory):<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from django.http import HttpResponse\ndef index(request):\n    return HttpResponse(\"Welcome to TechVidvan Django Tutorial\")<\/pre>\n<p>Here, we have imported a HttpResponse, and we have created a function named index which takes an argument request. We have used this index function in the urls.py file.<\/p>\n<p>This function takes an argument as a request and we are returning the HttpResponse ().<\/p>\n<p>Run the following command in the Visual Studio Code\u2019s terminal:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">python manage.py runserver<\/pre>\n<p>This will run your app, and you will see the following output.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/step-5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83860\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/step-5.png\" alt=\"Create first Django App\" width=\"1920\" height=\"1024\" \/><\/a><\/p>\n<p>So, we have just created our first Django app and also our first web page.<\/p>\n<h3>Summary<\/h3>\n<p>In this tutorial, we have learned to create our first Django app and launch our first web page. We have also worked with some of Django\u2019s files and learned more about the file structure.<\/p>\n<p>Always remember to activate the virtual environment before creating your app, otherwise, your app will not start. Carefully follow every single step mentioned in the article to create your app simply and effortlessly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will learn how to create, install and deploy our first Django app effortlessly. We will be working with some of the app and project files. We will learn the basics&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":83855,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3383],"tags":[3996,3997],"class_list":["post-83187","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-django","tag-create-django-app","tag-create-your-first-django-app"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Create Your First Django App in 5 Easy Steps - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn to create, install &amp; deploy Django app effortlessly. Work with the app &amp; project files. Learn how these files interact among themselves.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Your First Django App in 5 Easy Steps - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn to create, install &amp; deploy Django app effortlessly. Work with the app &amp; project files. Learn how these files interact among themselves.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-17T03:30:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Create-Your-First-Django-App.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create Your First Django App in 5 Easy Steps - TechVidvan","description":"Learn to create, install & deploy Django app effortlessly. Work with the app & project files. Learn how these files interact among themselves.","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:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Your First Django App in 5 Easy Steps - TechVidvan","og_description":"Learn to create, install & deploy Django app effortlessly. Work with the app & project files. Learn how these files interact among themselves.","og_url":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-08-17T03:30:04+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Create-Your-First-Django-App.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"How to Create Your First Django App in 5 Easy Steps","datePublished":"2021-08-17T03:30:04+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/"},"wordCount":835,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Create-Your-First-Django-App.jpg","keywords":["Create Django App","Create Your First Django App"],"articleSection":["Django Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/","url":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/","name":"How to Create Your First Django App in 5 Easy Steps - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Create-Your-First-Django-App.jpg","datePublished":"2021-08-17T03:30:04+00:00","description":"Learn to create, install & deploy Django app effortlessly. Work with the app & project files. Learn how these files interact among themselves.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Create-Your-First-Django-App.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Create-Your-First-Django-App.jpg","width":1200,"height":628,"caption":"Create Your First Django App"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/create-your-first-django-app\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"How to Create Your First Django App in 5 Easy Steps"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=83187"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83187\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/83855"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=83187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=83187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=83187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}