P
P
paveltrty2020-08-08 10:13:23
Django
paveltrty, 2020-08-08 10:13:23

admin won't open, how to fix?

when going to /admin writes Page not found

from django.shortcuts import render
from django.views.generic.base import View
from django.views.generic import DetailView, ListView
from .models import yarn

class yarnView(ListView):
  model = yarn
  queryset = yarn.objects.all() 
  template_name = "yarn/katalog.html"

class yarnDetail(DetailView):
  model = yarn
  template_name = "yarn/katalog_detail.html"
  slug_field = "url"
  

class Main(View):
  def get(self, request):
    return render(request, "yarn/index.html")

class delivery(View):
  def get(self, request):
    return render(request, "yarn/deliveri.html")

class bank(View):
  def get(self, request):
    return render(request, "yarn/bank.html")

class kontakt(View):
  def get(self, request):
    return render(request, "yarn/kontakt.html")

class In(View):
  def get(self, request):
    return render(request, "")

from django.db import models
from django.urls import reverse
class Matirial(models.Model):
  title = models.CharField('Название', max_length=150)
  description = models.TextField("Описание")
  url = models.SlugField(max_length=150, unique=True)
  def __str__(self):
    return self.title
class Color(models.Model):
  title = models.CharField('Название', max_length=150)
  description = models.TextField("Описание")
  url = models.SlugField(max_length=150, unique=True)
  def __str__(self):
    return self.title

class Metrag(models.Model):
  title = models.CharField('Название', max_length=150)
  description = models.TextField("Описание")
  url = models.SlugField(max_length=150, unique=True)
  def __str__(self):
    return self.title

class yarn(models.Model):
    title = models.CharField('Название', max_length=150)
    description = models.TextField("Описание")
    price = models.PositiveSmallIntegerField("Цена", default=0)
    numberInStock = models.PositiveSmallIntegerField("Количество в наличии", default=0)
    color = models.ManyToManyField(Color, verbose_name="Цвет")
    creator = models.CharField("Производитель", max_length=150)
    img = models.ImageField("Изображение", upload_to="img/")
    url = models.SlugField(max_length=150, unique=True)
    matirial = models.ManyToManyField(Matirial, verbose_name="Материал")
    def __str__(self):
    	return self.title

    def get_absolute_url(self):
    	return reverse('katalog_detail', kwargs={"slug": self.url})

from django.urls import path

from . import views

urlpatterns = [
    path('katalog', views.yarnView.as_view()),
    path('', views.Main.as_view()),
    path('delivery', views.delivery.as_view()),
    path('kontakt', views.kontakt.as_view()),
    path('bank', views.bank.as_view()),
    path('in', views.In.as_view()),
    path("<slug:slug>/", views.yarnDetail.as_view(), name="katalog_detail"),
]

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path("", include('polls.urls')),
    path('admin/', admin.site.urls),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-08-08
@paveltrty

1. Where is the admin connection in urlpatterns?
2. Read pep8 and https://docs.djangoproject.com/en/3.1/internals/co... about how to properly name classes.
3. Instead of such Views, TemplateView is well suited.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question