Creating an App in Django

Search for a command to run...

No comments yet. Be the first to comment.
This is a basic Django tutorial in which we will create an Authentication App, from scratch in Django 2.0 and Learn the Fundamental concepts of Django Framework.
In this section, we will learn what are Models in Django and how to use models.py to create a database table in Django. So in our previous section, we have successfully configured our account app. Let's see what are Models in Django. Model A Model i...
You've done it. I've done it. We've all done it.

Your AI Agent Has Amnesia. ByteRover Fixes It — Without Vectors Let's see how to built a customer support agent that remembers everything — using plain markdown files, BM25 search, zero embeddings, a

My GenAI cohort kicked off today, and what a first day! Right away we were reminded that AI isn’t magic — at its core, models like Generative Pretrained Transformers (GPT) are doing one simple thing:

Hello Folks👋, I Recently got Graduated🎓 in 2020, yep in the Pandemic. We all hit very hard by this Corona Pandemic and we all got stuck at home for very long. We all realize the Importance of Socializing, Fitness (Physically as well Mentally), Diet...

So after learning the basic commands of git in our previous section, let's see Git in action. If you already have a project to track your files then you can skip this section and if not then continue. Initializing a Repository from Non-existing Dire...

Now that our environment -- a "project" -- is set up, we're set to start doing work. In this section, we will learn what is an App in Django and we will create an account App to handle the user signup feature. So let's get started.
An App is a Web application that does something. So for every functionality, an app can be created like a completely independent module. Let's understand App in Django with this realistic example:
Say you are building an online shopping site (e-commerce site) in Django so our Project will consist of Apps like:
Cart:- Which would have logic for users selected items for purchase.
Products:- Which would have logic for products that the site is selling.
Profile:- Which would have logic for user information.
Each application you write in Django consists of a Python package that follows a certain convention. Django comes with a utility that automatically generates the basic directory structure of an app, so you can focus on writing code rather than creating directories.
Django apps are reusable i.e. a Django app can be used with multiple projects.
Components are almost independent
Multiple developers can work on different components
Debugging and code organization is easy.
To create your app, make sure you're in the same directory as **manage.py** and type this command:
python manage.py startapp account
That'll create a directory account, which is laid out like this:
account/
__init__.py
admin.py
apps.py
migrations/
__init__.py
models.py
tests.py
views.py
init.py - Just to make sure python handles this folder as a package.
admin.py - This file helps you make the app modifiable in the admin interface.
models.py - This is where all the application models are stored.
tests.py - This is where your unit tests are.
views.py - This is where your application views are (actual logic).
To consider the account app in your project you need to specify your app name in the INSTALLED_APPS list as follows in social/settings.py file.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#add the app name here
'account',
]
By default, INSTALLED_APPS contains the following apps, all of which come with Django:
django.contrib.admin -- The admin site. You'll use it shortly.
django.contrib.auth -- An authentication system.
django.contrib.contenttypes -- A framework for content types.
django.contrib.sessions -- A session framework.
django.contrib.messages -- A messaging framework.
django.contrib.staticfiles -- A framework for managing static files.
These applications are included by default as a convenience for the common case.
Some of these applications make use of at least one database table or if our app makes use of database table (models), though, so we need to create the tables in the database before we can use them. To do that, we use the following command:
python manage.py migrate
The migrate command looks at the INSTALLED_APPS setting and creates any necessary database tables according to the database settings in your social /settings.py file.
So in this section, we learn how to create an App in Django and how to configure the App inside the settings. In the next section, we will learn about **Models** and we will write our first **Model** in Django.