Django - Apps Life Cycle


Advertisements

A project is a sum of many applications. Every application has an objective and can be reused into another project, like the contact form on a website can be an application, and can be reused for others. See it as a module of your project.

Create an Application

We assume you are in your project folder. In our main “myproject” folder, the same folder then manage.py −

$ python manage.py startapp myapp

You just created myapp application and like project, Django create a “myapp” folder with the application structure −

myapp/
   __init__.py
   admin.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.

Get the Project to Know About Your Application

At this stage we have our "myapp" application, now we need to register it with our Django project "myproject". To do so, update INSTALLED_APPS tuple in the settings.py file of your project (add your app name) −

INSTALLED_APPS = (
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'myapp',
)

Useful Video Courses


Video

Build a Stock Market Web App With Python and Django

Best Seller

39 Lectures 3.5 hours

John Elder

Video

Build A Flashcard Website With Python and Django

36 Lectures 2.5 hours

John Elder

Video

Build a Weather App With Python and Django

28 Lectures 2 hours

John Elder

Video

Build An API With The Django Rest Framework Using Python

Best Seller

20 Lectures 1 hours

John Elder

Video

Build A Dental Website With Python and Django

Most Popular

35 Lectures 3 hours

John Elder

Video

Build Python Django Real Project: Django Web Development

Best Seller

79 Lectures 10 hours

Rathan Kumar

Advertisements