Django == 2.1 Python 3.5.7 Я пытаюсь сохранить форму администратора, и ее URL-адрес / admin / Landing / banner / add / , но при отладке он говорит, что это Landing / banner / add /
Page not found (404)
Request Method: POST
Request URL: http://********.****/admin/landing/banner/add/
Raised by: django.contrib.admin.options.add_view
Using the URLconf defined in mainapp.urls, Django tried these URL patterns, in this order:
^$ [name='index']
contact/
demo/
success/
^media/(?P<path>.*)$
^static/(?P<path>.*)$
admin/
Текущий путь, Landing / banner / add / , не соответствует ни одному из них.
urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('landing.urls')),
path('admin/', admin.site.urls),
]
посадочный urls.py
from django.urls import path
from django.conf.urls import include, url
from . import views
from django.views.static import serve
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^$', views.index, name='index'),
path('', include('contact.urls')),
url(r'^media/(?P<path>.*)$', serve, {
'document_root': settings.MEDIA_ROOT,
}),
url(r'^static/(?P<path>.*)$', serve, {
'document_root': settings.STATIC_ROOT,
}),
]
contact urls.py
from django.contrib import admin
from django.urls import path
from .views import ContactView, SuccessView, DemoView
urlpatterns = [
path('contact/', ContactView.as_view()),
path('demo/', DemoView.as_view()),
path('success/', SuccessView.as_view()),
]
Модель баннера, я не добавил метод get_absolute_url, я должен?
class SingleActiveModel(models.Model):
active = models.BooleanField(default=True)
class Meta:
abstract = True
def save(self, *args, **kwargs):
if self.active:
allActive = type(self).objects.filter(active=True)
if self.pk:
allActive = allActive.exclude(pk=self.pk)
allActive.update(active=False)
super(SingleActiveModel, self).save(*args, **kwargs)
class Banner(SingleActiveModel):
banner_title = models.CharField(max_length=255)
banner_text = models.TextField(max_length=600)
button_text = models.CharField(max_length=35, blank=True, null=True)
button_link = models.CharField(max_length=255, blank=True, null=True)
second_button_text = models.CharField(max_length=35, blank=True, null=True)
second_button_link = models.CharField(max_length=255, blank=True, null=True)
image = models.ImageField(upload_to=get_image_path, blank=True, null=True)
logo = models.ImageField(upload_to=get_image_path, blank=True, null=True)
timestamp = models.DateTimeField(default=timezone.now())
def __unicode__(self):
return self.banner_text
def __str__(self):
return self.banner_title
def __repr__(self):
return self.active
class BannerModelAdmin(admin.ModelAdmin):
inlines = [ ImagesInline, ]
list_display = ['banner_title', "__unicode__", 'active', "timestamp"]
list_filter = ['active', 'timestamp']
search_fields = ['banner_title', 'banner_text']
class Meta:
model = Banner
admin.site.register(Banner, BannerModelAdmin)