Answer the question
In order to leave comments, you need to log in
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})
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)
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
path('<str:slug>/', GetSitiViwe.as_view(), name='post_details'),
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question