简体   繁体   中英

Using request.body in Django compared to nodejs for building restful apis

I have just begun learning the Django framework, and my goal is too take this knowledge and use it to build a rest api. (I have considered using django-rest framework, but my job requires specifically Django). I have already learned a medium amount of nodejs, and for this I use express. I use the req.body to enable users to enter some information. In Django, how would I use this req.body property to allow a user to type information. This is purely for backend purposes (no frontend included). For example, sending a post request, and setting parameters.

Both Express and Django endpoints receive a reference to the request object. The APIs are of course different. Here is a rough mapping:

  • Query string parameters ( https://example.com/?foo=bar ):
  • Post data (posting foo=bar ):
    • Express : Depends on your middleware, but typically req.body.foo .
    • Django : request.POST["foo"]
  • Figuring out the request method is the same in both: request.method , which is a string like "POST" or "GET" .
request.body

in express is equivalent to

request.POST

in django

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM