Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 与#x27相反;管理彩色产品地图编辑';带参数';(';';,)';没有找到。已尝试1个模式:[';admin1/colorProductMap_edit/(?P<;id>;[0-9]+;)$&]_Python_Django_View_Django Views_Django Templates - Fatal编程技术网

Python 与#x27相反;管理彩色产品地图编辑';带参数';(';';,)';没有找到。已尝试1个模式:[';admin1/colorProductMap_edit/(?P<;id>;[0-9]+;)$&]

Python 与#x27相反;管理彩色产品地图编辑';带参数';(';';,)';没有找到。已尝试1个模式:[';admin1/colorProductMap_edit/(?P<;id>;[0-9]+;)$&],python,django,view,django-views,django-templates,Python,Django,View,Django Views,Django Templates,我是Django的新面孔,所以如果我的问题是愚蠢的,请考虑一下。所以我一直在练习Django,我遇到了tegards到NoReverseMatch的问题,我在stackoverflow中查看了答案,但仍然找不到哪里出了问题。你们能帮我一点忙吗 视图.py @login_required(login_url="admin-login") @user_passes_test(check_role_admin) def colorProductMap_edit(request, i

我是Django的新面孔,所以如果我的问题是愚蠢的,请考虑一下。所以我一直在练习Django,我遇到了tegards到NoReverseMatch的问题,我在stackoverflow中查看了答案,但仍然找不到哪里出了问题。你们能帮我一点忙吗

视图.py

@login_required(login_url="admin-login")
@user_passes_test(check_role_admin)
def colorProductMap_edit(request, id):
    instance = ColorProductMapping.objects.get(color_p_map_id=id)
    print(instance.color_id)
    form = ColorProductMapForm(instance=instance)
    if request.method == 'POST':
        form = ColorProductMapForm(request.POST, instance=instance)
        if form.is_valid():
            form.save()
            return redirect('/admin1/colorProductMap')
    else:
        form = ColorProductMapForm(instance=instance)

    return render(request, 'admin1/colorProductMap.html', {'form': form, 'instance': instance})
path('colorProductMap_edit/<int:id>', views.colorProductMap_edit, name="admin-color-product-map-edit"),
class ColorProductMapForm(forms.ModelForm):
    class Meta:
        model = ColorProductMapping
        fields = ['color_id', 'prod_id']
class ColorProductMapping(models.Model):
    color_p_map_id = models.AutoField("Color & Product Map ID", primary_key=True, auto_created=True)
    color_id = models.ForeignKey(Color, null=False, on_delete=models.CASCADE, verbose_name="Color ID")
    prod_id = models.ForeignKey(Product, null=False, on_delete=models.CASCADE, verbose_name="Product Id")
我在我的URL.py中与以下内容建立了适当的合作关系和连接。 url.py

@login_required(login_url="admin-login")
@user_passes_test(check_role_admin)
def colorProductMap_edit(request, id):
    instance = ColorProductMapping.objects.get(color_p_map_id=id)
    print(instance.color_id)
    form = ColorProductMapForm(instance=instance)
    if request.method == 'POST':
        form = ColorProductMapForm(request.POST, instance=instance)
        if form.is_valid():
            form.save()
            return redirect('/admin1/colorProductMap')
    else:
        form = ColorProductMapForm(instance=instance)

    return render(request, 'admin1/colorProductMap.html', {'form': form, 'instance': instance})
path('colorProductMap_edit/<int:id>', views.colorProductMap_edit, name="admin-color-product-map-edit"),
class ColorProductMapForm(forms.ModelForm):
    class Meta:
        model = ColorProductMapping
        fields = ['color_id', 'prod_id']
class ColorProductMapping(models.Model):
    color_p_map_id = models.AutoField("Color & Product Map ID", primary_key=True, auto_created=True)
    color_id = models.ForeignKey(Color, null=False, on_delete=models.CASCADE, verbose_name="Color ID")
    prod_id = models.ForeignKey(Product, null=False, on_delete=models.CASCADE, verbose_name="Product Id")
型号.py

@login_required(login_url="admin-login")
@user_passes_test(check_role_admin)
def colorProductMap_edit(request, id):
    instance = ColorProductMapping.objects.get(color_p_map_id=id)
    print(instance.color_id)
    form = ColorProductMapForm(instance=instance)
    if request.method == 'POST':
        form = ColorProductMapForm(request.POST, instance=instance)
        if form.is_valid():
            form.save()
            return redirect('/admin1/colorProductMap')
    else:
        form = ColorProductMapForm(instance=instance)

    return render(request, 'admin1/colorProductMap.html', {'form': form, 'instance': instance})
path('colorProductMap_edit/<int:id>', views.colorProductMap_edit, name="admin-color-product-map-edit"),
class ColorProductMapForm(forms.ModelForm):
    class Meta:
        model = ColorProductMapping
        fields = ['color_id', 'prod_id']
class ColorProductMapping(models.Model):
    color_p_map_id = models.AutoField("Color & Product Map ID", primary_key=True, auto_created=True)
    color_id = models.ForeignKey(Color, null=False, on_delete=models.CASCADE, verbose_name="Color ID")
    prod_id = models.ForeignKey(Product, null=False, on_delete=models.CASCADE, verbose_name="Product Id")
colorProductMap.html

{% extends 'admin1/layout/master.html' %}
{% block title %}Color Product Map{% endblock %}
{% block main %}
<h1>
    <center>Color Product Map</center>
</h1>
<div class="container">
    <div class="row">
        <div class="col-lg-2"></div>
        <div class="col-lg-10">
            {%if colorProductMap_show%}
            <button type="button" class="btn btn-primary mt-2" data-toggle="modal" data-target="#modal-primary">Add
                Color Product Mapping
            </button>
            <div class="modal fade" id="modal-primary">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title">Add Color Product Mapping</h4>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span></button>
                        </div>
                        <div class="modal-body mt-2">
                            <form action="{% url 'admin-color-product-map'%}" method="POST"
                                  enctype="multipart/form-data">
                                {% csrf_token %}
                                <table border="1" class="table table-bordered border border-info">
                                    <tr>
                                        <th>
                                            {{form.color_id.label_tag}}
                                        </th>
                                        <td>{{form.color_id}}</td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{form.prod_id.label_tag}}
                                        </th>
                                        <td>
                                            {{form.prod_id}}
                                        </td>
                                    </tr>
                                </table>
                                <div class="modal-footer justify-content-right">
                                    <input type="Submit" name="Submit" value="Submit" class="btn btn-outline-success">
                                    <button type="button" class="btn btn-outline-danger" data-dismiss="modal">Close
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                    <!-- /.modal-content -->
                </div>
                <!-- /.modal-dialog -->
            </div>
            <!-- /.modal -->

            <div class="container-fluid ">
                <div class="row">
                    <div class="card mt-2 border border-secondary">
                        <div class="card-header">
                            <h3 class="card-title ">Color Product Map Table</h3>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body">

                            <table class="table table-bordered border border-info">
                                <thead>
                                <tr>
                                    <th>Color Product Mapping Id</th>
                                    <th>Product ID</th>
                                    <th>Color ID</th>
                                    <th>Action</th>
                                </tr>
                                </thead>
                                <tbody class="justify-content-center">
                                {% for x in colorProductMap_show %}
                                <tr>
                                    <td>{{x.color_p_map_id}}</td>
                                    <td>{{x.prod_id}}</td>
                                    <td>{{x.color_id}}</td>
                                    <td><a href="{% url 'admin-color-product-map-edit' x.color_p_map_id %}"
                                           class="btn btn-outline-primary mt-2"><i
                                            class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
                                        <a href="{% url 'admin-color-product-map-delete' x.color_p_map_id %}"
                                           class="btn btn-outline-danger mt-2"><i
                                                class="fa fa-trash" aria-hidden="true"></i></a>
                                    </td>
                                </tr>

                                {% endfor %}

                                </tbody>
                            </table>

                        </div>
                        <!-- /.card-body -->
                        <div class="card-footer clearfix ">
                            <ul class="pagination pagination-sm m-0 justify-content-center">
                                {% if colorProductMap_show.has_previous %}
                                <li class="page-item"><a class="page-link"
                                                         href="?page={{colorProductMap_show.previous_page_number}}">
                                    Previous </a>
                                </li>
                                {% endif%}
                                {% for x in colorProductMap_show.paginator.page_range %}

                                {% if colorProductMap_show.number == x %}
                                <li class="page-item active"><a class="page-link" href="?page={{x}}">{{x}}</a></li>
                                {% else%}
                                <li class="page-item"><a class="page-link" href="?page={{x}}">{{x}}</a></li>
                                {% endif %}
                                {% endfor %}

                                {% if colorProductMap_show.has_next %}
                                <li class="page-item"><a class="page-link"
                                                         href="?page={{colorProductMap_show.next_page_number}}">
                                    Next </a>
                                </li>
                                {% endif %}
                            </ul>
                        </div>
                    </div>
                    <!-- /.card -->
                </div>
            </div>


            {%endif%}
            {% if instance %}
            <form action="{% url 'admin-color-product-map-edit' x.color_p_map_id %}" method="POST"
                  enctype="multipart/form-data">
                {% csrf_token %}
                 <table border="1" class="table table-bordered border border-info">
                                    <tr>
                                        <th>
                                            {{form.color_id.label_tag}}
                                        </th>
                                        <td>{{form.color_id}}</td>
                                    </tr>
                                    <tr>
                                        <th>
                                            {{form.prod_id.label_tag}}
                                        </th>
                                        <td>
                                            {{form.prod_id}}
                                        </td>
                                    </tr>
                                </table>
                    <input type="Submit" name="Submit" value="Submit" class="btn btn-success w-50"><br>
                <div class="modal-footer justify-content-between">
                    <button type="button" class="btn btn-outline-light" data-dismiss="modal">Close
                    </button>
                </div>
            </form>

            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
{%extends'admin1/layout/master.html%}
{%block title%}颜色产品映射{%endblock%}
{%block main%}
彩色产品图
{%if colorProductMap_show%}
添加
彩色产品映射
添加颜色产品映射
&时代;
{%csrf_令牌%}
{{form.color\u id.label\u tag}
{{form.color\u id}
{{form.prod\u id.label\u tag}
{{form.prod_id}
接近
彩色产品映射表
颜色产品映射Id
产品ID
颜色ID
行动
{colorProductMap_show%}
{{x.color\u p\u map\u id}
{x.prod_id}
{x.color\u id}
{%endfor%}
    {%如果colorProductMap\u show.has\u previous%}
  • {%endif%} {colorProductMap_show.paginator.page_range%} {%if colorProductMap_show.number==x%}
  • {%else%}
  • {%endif%} {%endfor%} {%如果colorProductMap\u show.has\u next%}
  • {%endif%}
{%endif%} {%if实例%} {%csrf_令牌%} {{form.color\u id.label\u tag} {{form.color\u id} {{form.prod\u id.label\u tag} {{form.prod_id}
接近 {%endif%} {%endblock%}

我做错了什么?我想我已经遵循了我能找到的每一条建议,但它仍然给了我错误。感谢您的帮助。多谢各位

您将表单标签写为:

<form action="{% url 'admin-color-product-map-edit' x.color_p_map_id %}" method="POST"
                  enctype="multipart/form-data">

谢谢大家的指导,我已经发现了我的错误

在html模板中,如下所示

<form action="{% url 'admin-color-product-map-edit' x.color_p_map_id %}" method="POST"
                  enctype="multipart/form-data">

这里我使用的是x.color\u p\u map\u id,其中x不是任何I