Name : Abdullah Numan Shakil.
Dept. of Computer Science & Engineering.
University of Rajshahi.
Create an empty folder "Practice". Inside the folder create virtual environment
python -m venv env
Activate the virtual environment
cd env
cd Scripts
activate
Go back to the project folder "Practice" and install Django and rest framework
pip install django
pip install djangorestframework
Create a new Django project "catproject"
django-admin startproject catproject
Run the project if it is working properly
python manage.py runserver
Create a new app "catapp"
python manage.py startapp catapp
Go to the settings.py file inside catproject and add 'catapp' and 'rest_framework' in INSTALLED_APPS
Go to the "catapp" folder.
Implement The model inside models.py
Create serializers.py and implement serializer including all fields of the model.
In views.py implement CRUD operations for the model
Create urls.py and define the urls
Go to the urls.py in "catproject" and include urls.py of the "catapp"
Install the module pip install drf-yasg
Go to settings.py and add this 'drf_yasg',
in INSTALLED_APPS
Go to urls.py in "catproject" and add the code snippet
from django.urls import re_path
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
schema_view = get_schema_view(
openapi.Info(
title="Dog API",
default_version='v1',
description="Documentation",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="contact@dogapp.local"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)
urlpatterns = [
path('documentation.json/', schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('documentation/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
For more details about documentation go to the website Link
Go to tests.py in "catapp" and implement the testing.
For running the tests.py write python manage.py test