我想在Django处理请求参数更优雅,这是我的代码:qazxsw poi
有了它,我可以在我的视图功能中使用这样的:
然后我运行了我的Django应用程序并在chrome中输入了url(def testparam(request):
name = request_get(request, 'name', required=True)
age = request_get(request, 'age', ptype=int, required=True)
print('name: ', name)
print('age: ', age)
return HttpResponse('test param run')
),但我仍然得到了“test param run”的响应。我希望我的django在request_get函数调用就像在flask框架中的abort函数时做出响应。有人可以帮帮我吗?
我通过使用http://127.0.0.1:8000/test/param提示自定义异常和异常中间件来解决问题