V
V
Vladislav ...2021-02-23 12:29:57
Django
Vladislav ..., 2021-02-23 12:29:57

How to display individual pages in django?

Good afternoon, tell me how to display separate pages in django such as: Contacts, About us, etc.
there is a model for creating pages

class SitiViwe(models.Model):
    title = models.CharField(max_length=255, verbose_name='Титул')
    slug = models.SlugField(max_length=255, verbose_name='Url', unique=True)
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='Дата созданиея')
    created_data = models.DateTimeField(auto_now=True, verbose_name='Дата изминения')
    author = models.CharField(max_length=255, verbose_name='Автор')
    content = models.TextField(blank=True, verbose_name='Контент')
    views = models.IntegerField(default=0, verbose_name='Кол-во просмотров')
    def __str__(self):
        return self.title

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

there is an admin panel
class SitiViweAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("title",)}
    save_as = True
    save_on_top = True
    list_display = (
        'id', 'title', 'slug',)
    list_display_links = ('id', 'title')
    search_fields = ('title',)



admin.site.register(SitiViwe, SitiViweAdmin)

there is a vyuha
class GetSitiViwe(DetailView):
    model = SitiViwe
    template_name = 'details.html'
    context_object_name = 'post'

    def get_context_data(self, *, object_list=None, **kwargs):
        context = super().get_context_data(**kwargs)
        self.object.views = F('views') + 1
        self.object.save()
        self.object.refresh_from_db()
        return context

urls.py
path('<str:slug>/', GetSitiViwe.as_view(), name='post_details'),

and in the template I can’t figure out how to display so that there is one link in the header and opens by slug in the footer, another one also opens by slug

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sanya Hihi Haha, 2021-02-23
@ValarMayar

Maybe this is what you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question