简体   繁体   中英

How to refer to images stored in SHA1 hash form in django template downloaded by scrapy

i used dynamic django scraper to scrape items from some site. I downloaded image and are saved in desired location but i cannot access them from django template. The images are saved in SHA1 hash. Is there a way to access them from django template?

In my models the images are saved as,

Image: u'http://www.market1/ScaledImages/180x180x2/Global-BlaBand_Bistro_kastikkeet.jpg'

but when i see the folder where i have saved them , the filename is in the form of SHA1 Hash.

In my django template i did

<img src="{{STATIC_URL}}Image/{{item.image}}">

But still , I can't access the image . However if i do

<img src="{{STATIC_URL}}Image/38ce4c28e9969cdcf02bf74293d512faf1dc37da.jpg">

ie refer to SHA1 hash i can access them.

Is there a way to access images without using hard-coded code? Thanks

SHA-1 is a simple cryptographic hash function,

why don't you just convert bellow url

Image: u' http://www.market1/ScaledImages/180x180x2/Global-BlaBand_Bistro_kastikkeet.jpg '

in sha-1 and then fine the image in directory with that SHA-1 ?

other then that you can simply override the image storage mechanism , and can store images with their url rather then SHA-1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM