G
G
gemlin2019-08-10 16:06:02
Django
gemlin, 2019-08-10 16:06:02

How to display data in html template?

Hello.
Please help me resolve this issue. I've watched a lot of videos, but I can't get an answer to my question.
I created a class in model.pu

class Store(models.Model):
    name = models.CharField(max_length=20,verbose_name="Имя магазина" )
    image = models.ImageField(upload_to = 'static/img',verbose_name="Фото")
    website = models.URLField(max_length=250, verbose_name="Сайт")
    def __str__(self):
        return self.name

Then I added it to urls.pu
from index.models import Store
admin.site.register(Store)

After the migration, a new function "Shops" appeared in the django admin panel. Added a new store there: Store names, store images, store website and everything is fine. The problem is, how do I display the titles, website, and store images in the template itself?
<div class="container">
  <h1 class="font-weight-light text-center text-lg-left mt-4 mb-0">Магазины</h1>
  <hr class="mt-2 mb-5">
  <div class="row text-center text-lg-left">
    <div class="col-lg-3 col-md-4 col-6">
      <a href="#" class="d-block mb-4 h-100">
            <img class="img-fluid img-thumbnail" rel="nofollow" target="_BLANK" src="{{ Store.image }}" alt="">
          </a>
<p> {{ Store.name }}</p>
<p> Website: {{ Store.Website }}</p>
    </div>
</div>
</div>

here is the piece of html itself, how can I display store images from the database in the Img field, as well as store names for I tried to write {{ Store.name }} nothing is displayed.
Thank you very much for your attention, I hope for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey_Dolg, 2019-08-10
@Andrey_Dolg

On the topic, you made a model and registered it in the admin panel (but who knows why in urls.py). It remains to create a method for rendering html in views.py and add paths and a method call from views to urls.py.
And so it’s worth going through the django tutorial, at least on django girls, at least the translation of the official documentation and horses with people will be safe.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question