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