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
    15.8K+ Learners
    4.41  (656)
    Dev C++ Tutorial
    1 hrs
    Beginner
    6.3K+ Learners
    4.43  (230)
    Hashing in Java
    2 hrs
    Intermediate
    6.4K+ Learners
    4.43  (168)
    Eclipse Tutorial
    1 hrs
    Beginner
    3K+ Learners
    4.47  (133)
    NoSQL Database
    2 hrs
    Beginner
    11.6K+ Learners
    4.52  (751)
    SQL Triggers for Beginners
    1 hrs
    Intermediate
    12.6K+ Learners
    4.45  (528)
    WordPress with Docker
    1 hrs
    Beginner
    8.8K+ Learners
    4.5  (471)
    C++ Tutorial
    2 hrs
    Beginner
    48.7K+ Learners
    4.43  (2839)
    OOPs Concepts in C++
    2 hrs
    Beginner
    30.8K+ Learners
    4.43  (1986)
    Robotic Process Automation
    3 hrs
    Beginner
    13K+ Learners
    4.6  (686)