我正在尝试直接从另一个视图调用一个视图(如果这可能的话)。我有一个看法:
def product_add(request, order_id=None):
# Works. Handles a normal POST check and form submission and redirects
# to another page if the form is properly validated.
然后我有第二个视图,它在数据库中查询产品数据并应该调用第一个视图。
def product_copy_from_history(request, order_id=None, product_id=None):
product = Product.objects.get(owner=request.user, pk=product_id)
# I need to somehow setup a form with the product data so that the first
# view thinks it gets a post request.
2nd_response = product_add(request, order_id)
return 2nd_response
由于第二个需要像第一个视图一样添加产品,所以我想知道是否可以从第二个视图中调用第一个视图。
我的目标只是将请求对象传递到第二个视图,然后将获得的响应对象依次返回给客户端。
非常感谢任何帮助,如果这是一种不好的方法,也可以批评。但随后一些指针.. 以避免干燥。
谢谢!
杰拉德。