Table of contents
1.
Introduction
2.
What are the benefits of using the Django app?
3.
What are the pre-installed apps that Django provides?
4.
How to create an app in Django?
4.1.
Method 1
4.2.
Method 2
5.
Frequently Asked Questions
6.
Key Takeaways
Last Updated: Mar 27, 2024

How to create app in Django

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Django that follows the model–template–views architecture is a python based free and open-source web framework, and It also enables the rapid development of secure and maintainable websites. Moreover, Django is versatile and can be used to develop any website, say its content management system, and avoid many security mistakes by the developers by enabling protection against vulnerability. Furthermore, it is portable and does not restrict developers to any particular server platform. In this article, we will look at making an app in Django. Here is an entirely separate module. We can make an app for every functionality.

What are the benefits of using the Django app?

  • These apps are reusable and can be used with multiple projects.
  • It contains almost independent components.
  • Many developers can handle different components.
  • It has a fantastic debugger tool, making it easy to debug and organize code.

What are the pre-installed apps that Django provides?

users get some pre-installed apps provided by Django. for viewing the pre-installed apps, follow the below-mentioned steps -

  • Navigate to project name, then go to seetings.py
  • Furthermore, now you will see INSTALLED_APP in the settings.py file.
  • Django provides listed apps names in the INSTALLED _APP for the developer's comfort.

 

# Application definition


INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles'
]
You can also try this code with Online Python Compiler
Run Code

How to create an app in Django?

So we will go through 2 different methods for making an app in Django.

Now starting with.

Method 1

  • Navigate to the manage.py file directory and enter the following command to make a basic app in the Django project.

 

python manage.py startapp projectApp
You can also try this code with Online Python Compiler
Run Code

Method 2

  • Navigate to the manage.py file directory and enter the following command to make a basic app in the Django project.

 

django-admin startapp projectApp
You can also try this code with Online Python Compiler
Run Code

 

This is how your directory structure will appear now.

  • Consider your app in the INSTALLED_APPS list in settings.py to consider your app in your project.

 

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'projectApp'
]
You can also try this code with Online Python Compiler
Run Code

 

  •  So, we have finally finished building an app, but to render it using URLs, it will have to be included in our main project so that URLs redirected to it can be rendered. Let us have a look at the following steps.


Move to project name, go to url.py and add the following code in the header.

 

From django.urls import include
You can also try this code with Online Python Compiler
Run Code

 

Now specify your app name for including your app urls for that type following code -

 

From django.contrib import admin
from django.urls import path, include


urlpatterns = [
path('admin/', admin.site.urls),
# Enter the app name in following
# syntax for this to work
path('', include("projectApp.urls")),
]
You can also try this code with Online Python Compiler
Run Code

 

  • In your app, to create URLs, models, views, etc., use MVT URLs to let them get automatically included in your main project.

Frequently Asked Questions

  1. What files should be present for starting a project in Django?
    mysite/, manage.py, mysite/urls.py, mysite/settings.py, and many more.
     
  2. For checking the outer mysite directory, what command should we run?
    py manage.py runserver

Key Takeaways

In this blog, we learned how to create an app in Django, methods we can follow, and the pre-installed apps that Django provides.

Don't come to a halt here. Check out our What is Machine Learning. You can also check out the blog on Data Science VS Artificial Intelligence VS Machine Learning VS Deep Learning.

Live masterclass