Opening of Django REST Framework tutorial

Author: HelloGitHub- Dream figure

Welcome to the second step of the HelloDjango full stack tutorial series-Django REST Framework tutorial!

First of all, congratulations on completing the first step of the HelloDjango full stack series of tutorials- Django Blog Tutorial (Second Edition) . In this tutorial, we learned the development method based on the traditional template engine. Rendering, the back-end programmers took over all the work of front-end development.

However, with the evolution of front-end technology, the development of separate front-end and back-end becomes more and more popular. Most of the companies with a small scale adopt the development method of separating the front end and the back end. In this development method, the back-end programmer only needs to pay attention to the business logic and return the business data through the interface, without knowing the front-end languages ​​such as HTML, CSS, and JavaScript Good programmers, although they do n’t need to write any more, they still have to understand); front-end programmers can use excellent js frameworks such as Vue and React and packaging tools such as Webpack to focus on page development. The bridge connecting them is the interface specification for data interaction between the front and back ends.

The most popular data interaction interface specification is of course a REST specification. REST stands for Representational State Transfer, which means "representational state transfer." To put it simply, in a RESTful architecture that conforms to REST principles, a URL represents a certain network resource. A network resource can refer to a blog post, a picture, a song, or a service. Resources are usually described in a standardized format. There are many formats for describing resources. For example, HTML documents are a form of description. Before this, XML was the most commonly used format, but now, there are more and more systems adopting the more lightweight description form of JSON. When the client interacts with the server, the resources are transferred in a certain described format. The client uses the HTTP protocol, making full use of HTTP protocol verbs (such as GET, POST) to express the intention to perform certain operations on the server-side resources, such as GET to obtain resources, POST to create new resources (can also be used to update Resources), PUT is used to update resources, and DELETE is used to delete resources.

Therefore, assuming that our system uses a RESTful architecture, for the front-end engineer, his job is to initiate a RESTful HTTP request to the back-end based on the rendered page, obtain the data returned by the interface, and render the front-end page. For the back-end programmer, it is to write an interface, interpret the request sent by the front end, operate the resource accordingly and return the data required by the front end.

How to interpret front-end requests, how to use specified formats to describe and transfer resources, etc. are all a series of standardized and repetitive tasks, so they can be implemented by a unified framework. Django itself does not provide such a processing framework, but django's third-party extension, django-rest-framework, is a set of frameworks specifically designed to develop RESTful interfaces that conform to REST specifications. It can be said that in this large environment where front and back ends are separated, django development is basically inseparable from django-rest-framework. Therefore, in the next tutorial, we will fully study the use of django-rest-framework.

Our example project will continue the blog developed in the Django Blog Tutorial (Second Edition) . If you follow the tutorial here, you can continue smoothly. It doesn't matter if you didn't watch the last tutorial, before the django-rest-framework tutorial officially starts, it will guide you how to run the blog step by step. Although the django-rest-framework tutorial continues the projects in the Django Blog Tutorial (Second Edition) , it is not much related in content. If you already have a django foundation (understand ORM and class views), you can start directly This tutorial. Of course, if you are a pure django novice, and you are still unfamiliar with the basic concepts in django, it is recommended to study the Django blog tutorial (second edition) first , lay the foundation, and then learn this tutorial with less effort.


Follow the public account to join the exchange group

Guess you like

Origin www.cnblogs.com/xueweihan/p/12670027.html