我正在尝试编写一个Django项目,其中我将名为“ cart”的应用程序中detail.html中的数据(“ cart”)传递给另一个应用程序(“ order”),并在其模板中显示它。但是我得到了下一个错误:
找不到带有参数'('',)'的'order_page'的反向。 1个 尝试使用的模式:['order \ / order_page \ /(?P [0-9] +)\ / $'] 与我的项目的这项任务有关的部分是:
detail.html
{% with totail_items=cart|length %}
{% if cart|length > 0 %}
My Shopping Order:
.................
{% for item in cart %}
{% with product=item.product %}
{{ product.name }}
<form action="{% url "cart:cart_add" product.id %}" method="post">
.............
<a href="{% url 'order:order_page' request.cart.id %}"> ORDER </a>
cart / views.py
def cart_add(request, product_id):
cart = Cart(request)
product = get_object_or_404(Product, id=product_id)
form = CartAddProductForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
cart.add(product=product, quantity=cd['quantity'], update_quantity=cd['update'])
return redirect('cart:cart_detail')
def cart_detail(request):
cart = Cart(request)
for item in cart:
item['update_quantity_form'] = CartAddProductForm(initial={'quantity': item['quantity'], 'update': True})
return render(request, 'detail.html', {'cart': cart})
order / urls.py
urlpatterns = [
path('order_page/<int:cart>/', views.OrderPage, name='order_page'),
]
order / views.py
from django.shortcuts import render
def OrderPage(request):
return render(request,'order/orderr.html', {'cart.id':cart.id})
能帮我吗? 理想情况下,我希望我从detail.html传递的数据显示在orderr.html中。