The Django API analysis

Source: Internet
Author: User

Below, I will carefully analyze the journey of a request:

The web side sends out a request message to the end of the response message to get the server.

1. Open the browser, enter the URL and go to the API page:

Http://127.0.0.1:8000/api/salt

2. Enter the command and press the Confirm button

According to Urlconf, the match is made from top to bottom, and finally the request message is handed to the Cmd method.

URL (r ' ^api/salt ', web_views.cmd,name= ' cmd '),
Here's a note: The Request object has a number of properties, with the highest number of post properties, which is an instance object of the class Dictionary object

At this point the Cmd method is an API that accepts and processes the request object and returns the response object to the HTML file

def cmd (Request): if request. Post:command = Commandform (Request. POST) A = print (request. POST) # host_ip = Request. Post.get (' host_ip ') func = Request. Post.get (' func ') # args = Request. Post.get (' args ') # command.host_ip = host_ip# Command.func = func# Command.args = args# command.save () result = Os.popen (fun c). Read () return render (Request, ' salt_api.html ', {' result ': result, ' post ': request. POST,}) Else:command = Commandform () return render (Request, ' salt_api.html ', {' form ': command})
The response object was sent to the HTML file

Here's how to show the response object in HTML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.