现在我想重用BundleList的post方法。要么找出绝对URL,然后使用requests.post(URL)
发送请求
第二种方法是在视图函数中通过return BundleList.as_view()(request)
重用。但是我不能设置request.data = data
。请求数据是不可变的
当我尝试使用
url = reverse_lazy(BundleList.as_view(), request=request)
print(f"{url = }")
它给了我:
NoReverseMatch at /generateSampleBundle/
Reverse for 'my_app.views.BundleList' not found. 'my_app.views.BundleList' is not a valid view function or pattern name.
BundleList是一个基于类的视图,带有get和post方法
drfurlpatterns = [ # DRF URL endpoints
path('bundles/', views.BundleList.as_view()),
]
有人能帮我吗
您应该为视图设置
name
,并在reverse_lazy()
中使用该名称例如:
然后
见docs
另外,要知道为什么
request.data
有时是不可变的see this question相关问题 更多 >
编程相关推荐