How to simulate a HTTP Post request from a django view without a template

前端 未结 5 1577
暖寄归人
暖寄归人 2021-02-13 19:11

I am writing views, not so keen to write templates right away.

But I need to test my program by submitting post requests.

How do i simulate HTTP Post from within

5条回答
  •  青春惊慌失措
    2021-02-13 19:49

    It sounds like you are looking for either a unit test or an acceptance test. Take a look at unittest which is part of the standard library.

    For quick ad hoc tests while developing web apps, I like to use curl. It's a simple command line tool that easily generates all sorts of HTTP requests. You can POST with a command like:

    curl -i -d field=value http://localhost:8080/sample/something
    

    Curl is available on a lot of platforms. Check it out at http://curl.haxx.se/

提交回复
热议问题