In this Django REST Framework lesson we are going to learn about Django REST Framework Creating Apps, also we are going to learn that how you can create django super user.
What are Django Apps?
Django apps are used to group application functionality. If you want to work with content from a database or user interactions you have to create and configure Django apps. a project can contain as many apps as you need. for example, if you have a project for a news website , you can create an app for sport news, another app for local news, another app for about information, another app for contact information , and create additional apps as they’re needed. there’s no hard rule to the number of apps in a project. whether to make code management simpler or delegate app work to a team, the purpose of Django apps is to group application functionality to make work easier. Django apps are normally contained in sub directories inside a project. This approach makes it easier to use Python references and naming conventions.
Now let’s create our App, first of all change directory to your Project and then use startapp command followed by the name of your app, in here we have given our app name as api.
1 |
cd APIProject |
1 |
python manage.py startapp api |
After creating of the App, you need to add your app in the INSTALLED_APPS of settings.py file.
1 2 3 4 5 6 7 8 9 |
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'api', #newly added app ] |
This is the Project Structure of Django App.
- __init__.py .- Python file to allow app packages to be imported from other
directories. Note __init__.py is not a Django specific file, it’s a generic file used in
almost all Python applications. - migrations.- Directory that contains migrations applied to the app’s database
definitions (i.e., model classes). - admin.py .- File with admin definitions for the app – such definitions are needed to
access model class instances from the Django admin. - apps.py .- File with configuration parameters for the app.
- models.py .- File with database definitions (i.e., model classes) for the app.
Also we are going to create a super user in Django, you can give your username and password.
1 |
python manage.py createsuperuser |
After that you can go to this url http://localhost:8000/admin/.