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.