- Installing django and django rest framework.
- creating Models
- creating Serializers
- creating views
- creating urls
- Our API is ready
-
Add 'rest_framework' in installed apps of settings.py
-
Create a new app using 'django-admin startapp app1' and then that app in installed apps of settings.py.
-
Create a new Model in models.py and add fields as your needs.
-
Now create a new file named serializers.py in app folder and import your model here.
-
create a serializer in serializers.py using Meta data of model:
-
Now import both model and serializer in views.py and create viewset of model:
-
Now in urls.py of app import 'viewset' here and create a router using routers method of rest_framework
-
Now register that router using url and viewset (i.e router.register(r"url", viewsetname))
-
Now apply migrations
-
Now run server using 'python manage.py runserver' and go to url which we created for router (i.e /companies in our case).