Django

Creating a Django based application:

Creating a Django based application:

In the previous section, we created the project subfolder “firstproject”. You need to navigate to that folder and then use the following code:

$ python manage.py startapp firstapp

With the help of the above code, you can create an application named “firstapp” and the structure of the application will be like this:

firstapp/
    __init__.py
    admin.py
    models.py
    views.py
tests.py

The files that come under firstapp folder are described below:

__init__.py: This file is used to initialize python for every package in this folder. 
admin.py: The file is used to modify the app with the help of the admin interface.
models.py: In this file, all the application models are stored.
views.py: This file stores application views.
tests.py: This file is intended for unit tests. 

Now you have to add the information of our application in the Django Project. To do this, you will be updating a tuple named INSTALLED_APPS in the settings.py file of the project:

INSTALLED_APPS = (
    ‘django.contrib.admin’,
    ‘django.contrib.auth’,
    ‘django.contrib.contenttypes’,
    ‘django.contrib.sessions’,
    ‘django.contrib.staticfiles’,
    ‘django.messages’
    ‘firstapp’,
)

The code shown above will register the application you just created in the Django project. 

Django - Admin Interface
Admin interfaces are always useful to manage all the content of a website or web app. Django provides a ready-made admin user interface that you can use to manage your web project. Based on the project models, the admin interface is automatically generated by Django. 

Activation of admin interface:

Whenever you create a project in Django, the admin app is automatically enabled by default and you can also see it in the tuple ‘INSTALLED_APPS’ in the settings.py file. 

INSTALLED_APPS = (
    ‘django.contrib.admin’,
    ‘django.contrib.auth’,
    ‘django.contrib.contenttypes’,
    ‘django.contrib.sessions’,
    ‘django.contrib.staticfiles’,
    ‘django.messages’
    ‘firstapp’,
)

You can also access the same on the live server by visiting the URL: ‘localhost:8000/admin/’
After you visit this URL, it may ask you for login credentials and if there’s no user login id is created, then you can create one by using the command below in Windows PowerShell:

python manage.py createsuperuser

After that you can access the admin login page by using the command below:

python manage.py runserver

This will open the admin login page where you can enter the credentials you just used for creating a new superuser id that will take you to the admin dashboard. 

By following the steps described above, you can access the admin interface of your application in Django. 
 

Top course recommendations for you

    Turbo C++
    1 hrs
    Beginner
    13.6K+ Learners
    4.44  (494)
    Dev C++ Tutorial
    1 hrs
    Beginner
    5.6K+ Learners
    4.46  (202)
    Hashing in Java
    2 hrs
    Intermediate
    5.7K+ Learners
    4.42  (130)
    Eclipse Tutorial
    1 hrs
    Beginner
    2.6K+ Learners
    4.45  (107)
    NoSQL Database
    2 hrs
    Beginner
    9.1K+ Learners
    4.56  (394)
    What is SQL Triggers?
    1 hrs
    Intermediate
    10.9K+ Learners
    4.44  (383)
    WordPress with Docker
    1 hrs
    Beginner
    7.1K+ Learners
    4.49  (292)
    C++ Tutorial
    2 hrs
    Beginner
    43.9K+ Learners
    4.46  (2125)
    OOPs Concepts in C++
    2 hrs
    Beginner
    27.6K+ Learners
    4.46  (1517)
    Robotic Process Automation
    3 hrs
    Beginner
    10.8K+ Learners
    4.62  (487)