Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.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 未找到页面(404)更新产品_Python_Django_Web_Post_Get - Fatal编程技术网

Python 未找到页面(404)更新产品

Python 未找到页面(404)更新产品,python,django,web,post,get,Python,Django,Web,Post,Get,我不知道我的设置有什么问题 我的URL.py from django.urls import path from . import views app_name = 'shop' urlpatterns = [ path('', views.product_list, name='product_list'), path('<slug:category_slug>/', views.product_list, name='product_list_by_cate

我不知道我的设置有什么问题 我的URL.py

from django.urls import path
from . import views

app_name = 'shop'

urlpatterns = [
    path('', views.product_list, name='product_list'),

    path('<slug:category_slug>/', views.product_list, name='product_list_by_category'),

    path('<int:id>/<slug:slug>/', views.product_detail, name='product_detail'),

    path('shop/Create_Product/', views.Create_Product, name='Create_Product'),

    path('shop/product/Edit_Product/', views.Edit_Product, name='Edit_Product'),        

]
Models.py

class Product(models.Model):
    category = models.ForeignKey(Category,
                                 related_name='products',
                                 on_delete=models.CASCADE)
    name = models.CharField(max_length=200, db_index=True)
    slug = models.SlugField(max_length=200, db_index=True)
    image = models.ImageField(upload_to='products/%Y/%m/%d',
                              blank=True)
    description = models.TextField(blank=True)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    available = models.BooleanField(default=True)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    class Meta:
        ordering = ('name',)
        index_together = (('id', 'slug'),)

    def __str__(self):
        return self.name

    def get_absolute_url(self):
            return reverse('shop:product_detail', args=[self.id, self.slug])
Views.py

@staff_member_required
def Edit_Product(request, id=None):
    instance = get_object_or_404(Product, id=id)
    if request.method == "POST":
        form = EditProduct(request.POST, instance=instance)
        if form.is_valid():
            product = form.save(commit=False)
            product.save()
            return redirect('shop/product/detail.html')
    else:
        form = EditProduct(instance=instance)
    return render(request,'shop/product/Edit_Product.html', {'form': form, 'product': instance})
请任何人帮帮忙,我是django的一个真正的noob,我查看了互联网没有答案,我试图改变url模式,但也没有希望,有时它显示缺少一个关键位置参数,有时显示404错误

在这种情况下,您的url需要如下所示:

path('shop/product/Edit_Product/<int:id>', views.Edit_Product, name='Edit_Product'),

传递要编辑的产品的id。

您的控制台中是否有任何错误消息?如果id未返回对象,您已请求404,因此请在查询实例之前尝试打印id。PrintFuUpdate对象{id}
def Edit_Product(request, id=None):
    instance = get_object_or_404(Product, id=id)
path('shop/product/Edit_Product/<int:id>', views.Edit_Product, name='Edit_Product'),
path('shop/product/Edit_Product/', views.Edit_Product, name='Edit_Product'),