Django 与#x27相反;创建ordercontent';带参数';(';';,)';没有找到。尝试了1种模式:[';存储/创建\\-ordercontent/(?P<;order\u id>;[^/]+;)$&]

Django 与#x27相反;创建ordercontent';带参数';(';';,)';没有找到。尝试了1种模式:[';存储/创建\\-ordercontent/(?P<;order\u id>;[^/]+;)$&],django,django-templates,django-urls,Django,Django Templates,Django Urls,我是Django的新手。我正在尝试将id从第一个url传递到第二个url 找不到参数为“(“”,)”的“create ordercontent”的相反项。尝试了1个模式:[“存储/创建\-ordercontent/(?P[^/]+)$”] url.py path('list-ordercontent/<order_id>', OrdercontentListView.as_view(), name='list-ordercontent'), path('create-ordercon

我是Django的新手。我正在尝试将id从第一个url传递到第二个url

找不到参数为“(“”,)”的“create ordercontent”的相反项。尝试了1个模式:[“存储/创建\-ordercontent/(?P[^/]+)$”]

url.py

path('list-ordercontent/<order_id>', OrdercontentListView.as_view(), name='list-ordercontent'),
path('create-ordercontent/<order_id>', create_ordercontent, name='create-ordercontent'),
在list-ordercontent.html中,我试图使用相同的order\u id来传递我想要的变量,但它不正确。我想知道如何将order_id用于另一个url,在我的程序中,它是用于创建的url

<div class="breadcrumbs">
<div class="breadcrumbs-inner">
    <div class="row m-0">
        <div class="col-sm-4">
            <div class="page-header float-left">
                <div class="page-title">
                    <h1>Dashboard</h1>
                </div>
            </div>
        </div>
        <div class="col-sm-8">
            <div class="page-header float-right">
                <div class="page-title">
                    <ol class="breadcrumb text-right">
                        <li><a href="#">Dashboard</a></li>
                        <li><a href="#">Order</a></li>
                        <li class="active">
                            <a>{{ ordercontent.order.id }}</a>
                            <a>Content</a>
                        </li>
                    </ol>
                </div>
            </div>
        </div>
    </div>
</div>

仪表板
  • # 名称 类型 供应商 数量 行动 {%if ordercontent%} {ordercontent%中的ordercontent为%1} {{ordercontent.order.id} {{ordercontent.product.name} {{ordercontent.product.ptype} {{ordercontent.product.supplier} {{ordercontent.amount} {%endfor%} {%else%} 没有内容 {%endif%}
  • 列表视图
    不会将视图接收到的关键字参数添加到上下文中,如果您希望它们位于上下文中,您应该通过覆盖
    获取上下文数据来自己添加它们

    类OrdercontentListView(ListView):
    模型=订单内容
    template_name='store/list_ordercontent.html'
    上下文\对象\名称='ordercontent'
    def get_queryset(自我):
    模型=订单内容
    order=self.kwargs['order\u id']#无需访问'request.resolver\u match.kwargs',它们存在于'self.kwargs'中`
    返回model.objects.filter(订单=订单)
    def获取上下文数据(自身,**kwargs):
    context=super()。获取上下文数据(**kwargs)
    上下文['order\u id']=self.kwargs['order\u id']
    返回上下文
    
    您面临什么错误??您可以添加更多信息吗?当我尝试打开url时,请创建ordercontent。找不到参数“(“”,)”的“create ordercontent”的错误与此相反。尝试了1个模式:[“存储/创建\\-ordercontent/(?P[^/]+)$”]显示模板完整代码此模式是。我显示了我的完整代码。从何处获取此order\u id变量
    <div class="breadcrumbs">
    <div class="breadcrumbs-inner">
        <div class="row m-0">
            <div class="col-sm-4">
                <div class="page-header float-left">
                    <div class="page-title">
                        <h1>Dashboard</h1>
                    </div>
                </div>
            </div>
            <div class="col-sm-8">
                <div class="page-header float-right">
                    <div class="page-title">
                        <ol class="breadcrumb text-right">
                            <li><a href="#">Dashboard</a></li>
                            <li><a href="#">Order</a></li>
                            <li class="active">
                                <a>{{ ordercontent.order.id }}</a>
                                <a>Content</a>
                            </li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div class="row">
    <div class="col-xl-12">
        <div class="card">
            <div class="card-body">
                <div class="box-title float-left">
                    <h4>Order Content</h4>
                </div>
                <div class="box-title float-right">
                    <a href="{% url 'create-ordercontent' order_id %}">Add Product</a>
                </div>
            </div>
            <div class="card-body--">
                <div class="table-stats order-table ov-h">
                    <table class="table ">
                        <thead>
                            <tr>
                                <th class="serial">#</th>
                                <th>Name</th>
                                <th>Type</th>
                                <th>Supplier</th>
                                <th>Amount</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% if ordercontent %}
                            {% for ordercontent in ordercontent %}
                            <tr>
                                <td class="serial">{{ ordercontent.order.id }}</td>
                                <td>{{ ordercontent.product.name }}</td>
                                <td>{{ ordercontent.product.ptype }}</td>
                                <td>{{ ordercontent.product.supplier }}</td>
                                <td>{{ ordercontent.amount }}</td>
                            </tr>
                            {% endfor %}
                            {% else %}
                                <tr><td>No Content</td></tr>
                            {% endif %}
                        </tbody>
                    </table>
                </div> <!-- /.table-stats -->
            </div>
        </div> <!-- /.card -->
    </div>  <!-- /.col-lg-8 -->