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
    16.1K+ Learners
    4.41  (698)
    Dev C++ Tutorial
    1 hrs
    Beginner
    6.3K+ Learners
    4.44  (243)
    Hashing in Java
    2 hrs
    Intermediate
    6.5K+ Learners
    4.43  (193)
    Eclipse Tutorial
    1 hrs
    Beginner
    3K+ Learners
    4.49  (141)
    NoSQL Database
    2 hrs
    Beginner
    12.1K+ Learners
    4.5  (980)
    SQL Triggers for Beginners
    1 hrs
    Intermediate
    12.9K+ Learners
    4.47  (590)
    WordPress with Docker
    1 hrs
    Beginner
    9K+ Learners
    4.52  (517)
    C++ Tutorial
    2 hrs
    Beginner
    49.2K+ Learners
    4.43  (2981)
    OOPs Concepts in C++
    2 hrs
    Beginner
    31.3K+ Learners
    4.43  (2144)
    Robotic Process Automation
    3 hrs
    Beginner
    13.2K+ Learners
    4.6  (743)