Answer the question
In order to leave comments, you need to log in
How to create dynamically resizable pages in Django?
I started learning Python + Django, I decided to write a simple bolg... There was a problem with the dynamically changing URL of articles from the database. On the Internet, I found instructions on what and how, prescribed it, throws an error page not found.
Here is my code:
models:
class Gadgets(models.Model):
title = models.CharField('Название', max_length=255)
text = models.TextField('Текст', max_length=1000000)
image = models.ImageField('Изображение', upload_to='images', blank=True, null=True)
author = models.CharField('Автор', max_length=255)
def __str__(self):
return '{} | {} '.format(self.title, self.author)
class Meta:
verbose_name = 'Гаджет'
verbose_name_plural = 'Гаджеты'
def gadgets(request):
gadget = Gadgets.objects.order_by('-id')
data = {
'gadget': gadget
}
return render(request, 'gadgets/gadgets.html', data)
class GadgetDetailView(DetailView):
model = Gadgets
template_name = 'gadgets/gadgets_detail.html'
context_object_name = 'gadgets'
urlpatterns = [
path('', views.gadgets),
path('<int:pk', views.GadgetDetailView.as_view(), name='gadgets-detail')
]
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