A
A
Alexander2021-02-24 18:34:21
Django
Alexander, 2021-02-24 18:34:21

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 = 'Гаджеты'


views:
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'


urls:
urlpatterns = [
    path('', views.gadgets),
    path('<int:pk', views.GadgetDetailView.as_view(), name='gadgets-detail')
]


Can someone tell me where the error is, I will be very grateful, thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2021-02-24
@Oleksandr_S

'<int:pk'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question