Django REST
About Lesson

In this Django REST Framework we are going to learn about Django REST Framework Function API View, Let’s see how we can write some API views using our new Serializer class. For the moment we won’t use any of REST framework’s other features, we’ll just write the views as regular Django views.

 

 

Open your views.py file in your api app and add this code, basically in here we are going to list all the articles.

 

 

 

Open your urls.py file and map view function to the url.

 

 

 

Now run your django project and go to http://localhost:8000/articles/, you will see the list of articles.

Django REST Framework Function API View
Django REST Framework Function API View

 

 

 

Also you can post a new data, for this we are going to open Postman and we want to add a data. because we want to be able to POST to this view from clients that won’t have a CSRF token we need to mark the view as  csrf_exempt , this isn’t something that you’d normally want to do, and REST framework views actually use more sensible behavior than this, but it’ll do for our purposes right now.

 

 

Now you can post your data to your backend.

 

Also we are going to add our update and delete methods in here.

 

 

 

Open your urls.py file and map view function to the url.

 

 

 

Go to http://localhost:8000/articles/2/, you will see your second article.

Django REST
Django REST