In background development, it is often necessary to check whether the interface is working properly, which is very convenient to use Postman.

Postman website: Postman

Take python + Django development background as an example.

Register an account, and if you get an error that you can’t connect to the Postman server, restart the program.

Then select Environment and create a new one

You can leave key-value blank if you do not need it.

Key points:

Back-end code:

def savestudentinfo(request) : Save student information to database
    # userID Name Some items have been omitted for introduction purposes
    if request.method == "POST":
        ip = getIP(request)
        info = json.loads(request.body)
        userid = info['userid']
        name = info['name'] # Student name
        
        # process the field
        try:
            user = UserInfo.objects.get(userid=userid)
            user.name = name # update the name field
            user.save()
            message ="Saved successfully"
            return HttpResponse(json.dumps({"msg": message}, ensure_ascii=False), content_type='application/json')
        except:
            if message =="":
                message = "Save failed"
            return HttpResponse(json.dumps({"msg": message}, ensure_ascii=False), content_type='application/json')
Copy the code

Also need to modify:

Main project urls.py (add routing path)

path('savestudentinfo/',views.savestudentinfo),
Copy the code

Middleware.py (block section, small projects you create can be ignored)

Models.py (if you changed the mysql database first, you need to generate the statement with the reverse command and add it to the models.py)