urls.py 有效,但是当我使用 <int:id> 更新特定项目时,出现 "Current path didn't match any of these" 错误

urls.py works but when I use <int:id> to update a particular item then I get "Current path didn't match any of these" error

我的 urls.py 在尝试阅读或创建新项目时有效。但是当尝试更新现有项目时,我会执行以下操作: 在 app/urls.py:

...
path('update_goals/<int:id>', update_goals, name='update_goals'),

在views.py中:

def update_goals(request, id):
    item = Items.objects.get(id=id)
    form = ItemFilterForm(request.POST or None, instance=item)
    if form.is_valid():  # validate the form
        form.save()
        return redirect(list_items)
    return render(request, 'items-form.html', {'form': form, 'item': item})

在models.py中:

class Items(models.Model):
    id = models.AutoField(db_column='ID', primary_key=True)
    company = models.CharField(null=True, db_column='Company', max_length=40, blank=True)  # Field name made lowercase.
    ...
    class Meta:
        managed = False
        db_table = 'Items'
        verbose_name_plural = 'Items'

html:

        {% for i in item %}
        <a href="{url 'update_goals i.id'}">
                <li>{{i.company}}</li>
                ...
        </a>
        {% endfor %}

我用来读取当前项目和创建新项目的其他路径有效,但只有更新无效。

错误:

Page Not Found(404)
Request URL:    http://127.0.0.1:8000/%7Burl%20'update_goals%20i.id'%7D
Using the URLconf defined in app1.urls, Django tried these URL patterns, in this order:

...
update_goals/<int:id> [name='update_goals']
admin/
The current path, {url 'update_goals i.id'}, didn't match any of these.

可能与 ID 列有关,但我尝试使用 update_goals/<str:company> abd i.company 以及它仍然给出相同的错误。

# You just need to change url in html file content

{% for i in item %}
<a href="{% url 'update_goals' id=i.id %}">
        <li>{{i.company}}</li>
        ...
</a>
{% endfor %}