L
L
Leonid Tyuchkalov2020-02-24 13:40:47
Django
Leonid Tyuchkalov, 2020-02-24 13:40:47

How to get link in HTML via dlango?

How can I get the link of the image I want? There is a model:

class Tour(models.Model):
    name = models.CharField('Место',max_length=50)
    bg = models.ImageField('Фон', upload_to='media/')

There is a view:
def tour(request):
    places = Tour.objects.all()
    context = {'places': places}
    return render(request, 'tour/index.html', context)

I need to substitute the image I need in HTML:
url("{{ bgs.bg.url }}")
For example, now I need 1, I will go to another page, there will be a third one, and so on.
When I go through the pages, the link does not change, because pictures in the layout on one page, they just change

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question