Can I factor a small piece of html code with Django template ?
I have, for example, a lot of images like this:
<img src="/xxxx/xxxx/xxxxxx.jpg">
Can I replace that by {{ image_xxx }} ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Create a custom template tag:
You can use this in your template as follows:
The value
001is then passed to the variablevalueand you can use it to construct the string that contains the image path (i.e.,"/xxxx/xxxx/xxxxxx.jpg").