Django adds% 2f instead of / to the template for the image field

I have a few problems with the django template with mimetype = "text / plain".

Firstly, the s3 url part is rendering with: 80 at the end, and then the actual image URL is rendering with "% 2f" in the replacement of each slash.

object.image.url 

I tried safe and other custom tags to replace "% 2f" and it just doesn't work

 #what I have http://blahblah.s3.amazonaws.com:80/navigation%2Fprimary%2Fimage.jpg #what I want http://blahblah.s3.amazonaws.com/navigation/primary/image.jpg 

The user tag I tried next is safe:

 import re from django import template register = template.Library() def reslash (value): return value.replace('%2f', '/') register.filter('reslash', reslash) 

used as follows:

 {{ object.image.url|reslash }} 

But that will not work. Thanks

+4
source share
1 answer

Django automatically html deletes all variables in the templates. To insert the value of a variable without escaping, you must use the safe filter to tell django that the value should not be automatically escaped as follows:

 {{ object.image.url|safe }} 
0
source

Source: https://habr.com/ru/post/1343853/


All Articles