Django项目使用postman测试post请求时候出现报错解决

问题描述——RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set. Django can’t redirect to the slash URL while maintaining POST data. Change your form to point to 127.0.0.1:8000/film/register/ (note the trailing slash), or set APPEND_SLASH=False in your Django settings.

Django项目使用postman测试post请求时候出现报错解决_postman

问题原因

错误分析:

因为定义的是post请求,pots请求一般是要携带参数进行提交,后面表单验证,但是测试没有写表单验证数据,只有一个post请,这个时候要给url地址末尾加上/,或者修改settings:APPEND_SLASH=False.

解决方法

post请求代码

Django项目使用postman测试post请求时候出现报错解决_django_02

view视图代码

Django项目使用postman测试post请求时候出现报错解决_postman_03

解决post请求不成功方法:

RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set.
提示form的action地址最后不是/结尾的,而且APPEND_SLASH的值是Ture

将from的action地址改为/结尾的就可以了
或者
修改settings:APPEND_SLASH=False

Django项目使用postman测试post请求时候出现报错解决_表单验证_04

问题解决