How can I show the image boy in the long-range template?

Asked 2 years ago, Updated 2 years ago, 48 views

Hi, everyone. This is a question about django. My question is how to display the image on the long-range template like the model related to the image. I'm making a website that shows a list of Korean actresses using the data I crawled The name and image of the actress have been downloaded first. First, you have the name model and the image_paths model with the local path of the downloaded image (the two models have the same order of downloaded data) and the image folder with the actual image. (Mismatch order with image_paths, each file name is the same as image_ptpath) But it's stuck from here

class images(models.Model):
    name = models.CharField(max_length=30)
    image_urls = models.CharField(max_length=200)
    images = models.TextField()
    image_paths = models.TextField(null=True)

questions,

How do I display the pictures in the image folder in the Jango template, just like the data sequence in the above models?

I really don't know ㅠ<

django

2022-09-21 18:20

1 Answers

That model builds up in the database in order.

Pictures are sorted in a folder by file name order (or something else)

So if django calls me in order,

I will import the files in the folder in the order in which they are stored in the database.

Just

in the template
<% for image in images %>
    <img src="{{ image.image_paths }}" alt="{{ image.name }}">
<% endfor %>

You can bring it like this

If you are referring to the order of file names, not the order stacked in the database,

I think you can use order by file name in ascending orderYo


2022-09-21 18:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.