Using the URLconf defined in myshop.urls, Django tried these URL patterns, in this order:
^admin/ ^$ [name='index']
^admin/ ^login/$ [name='login']
^admin/ ^logout/$ [name='logout']
^admin/ ^password_change/$ [name='password_change']
^admin/ ^password_change/done/$ [name='password_change_done']
^admin/ ^jsi18n/$ [name='jsi18n']
^admin/ ^r/(?P<content_type_id>\d+)/(?P<object_id>.+)/$ [name='view_on_site']
^admin/ ^auth/group/
^admin/ ^auth/user/
^admin/ ^sites/site/
^admin/ ^(?P<app_label>auth|sites)/$ [name='app_list']
The current path, admin/myshop/Product/add/, didn't match any of these.
我基本上是django的初学者并创建我的django商店应用程序。我输入网址http://127.0.0.1:8000/admin/myshop/Product/add/来收到此错误 我的admin.py看起来像这样
from django.contrib import admin
from .models import Category, Product
class CategoryAdmin(admin.ModelAdmin):
list_display=['name','slug']
prepopulated_fields={'slug':('name',)}
admin.site.register(Category, CategoryAdmin)
class ProductAdmin(admin.modelAdmin):
list_display=['name','slug','category','price','stock','avialable','created','updated']
list_filter=['available','created','updated','category']
list_editable=['price','stock','available']
prepopulated_fields=['slug':('name',)}
admin.site.register(Product, ProductAdmin)
这是我的models.py文件
from django.db import models
# Create your models here.
from django.core.urlresolvers import reverse
class Category(models.Model):
name = models.Charfield(max_length=200, db_index=True)
slug = models.Slugfield(max_length=200, db_index=True, unique=True)
class Meta:
ordering = ('name',)
verbose_name = 'category'
verbose_name_plural = 'categories'
def__str__(self):
return self.name
def get_absolute_url(self):
return reverse('shop:product_list_by_category', args=[self.slug])
Class product(models.Model):
category=models.ForeignKey(Category, related_name='products')
name=models.CharField(max_length=200, db_index=True)
slug=models.SlugField(max_length=200, db_index=True)
image=models.ImageField(upload_to'product/%Y/%m/%d',blank=True)
description=models.TextField(blank=True)
price=models.DecimalField(max_digits=10, decimal_places=2)
stock=models.PositiveIntegerField()
available=models.BooleanField(default=True)
created=models.Datetimefield(auto_now_add=True)
updated=models.DatetimeField(auto_now=True)
Class Meta:
ordering=('-created',)
index_togetther=(('id','slug'),)
def__str__(self):
return self.name
def get_absolute_url(self):
return reverse('shop:product_detail', args=[self.id,self.slug)
我试着检查一切,但一切看起来都不错