0

I need to create a path in an HTML code that is used to generate a download link.

   {% for data in all_data %}
   {% path_zip = '/home/harish/Desktop/cvision/users_output_files/{0}.zip'.format(data.id) %}
      <tr>
          <td> {{data.id}} </td>
          <td> {{data.childname}} </td>
          <td> {{data.age}} </td>
          <td> {{data.gender}} </td>
          <td> <a href={{path_zip}} download></a> </td>
      </tr>
  {% endfor %}

But this code is not working. And the following is the error.

Invalid block tag on line 40: 'path_zip', expected 'empty' or 'endfor'. Did you forget to register or load this tag?

How do I solve it?

2
  • The absolute path here is really a big problem, will it work for other users too? Commented Jan 25, 2020 at 8:01
  • Right now I just need to test it on my local computer. Commented Jan 26, 2020 at 6:58

1 Answer 1

1

You cant, and dont need to write python here, you could use a custom template tag but it would be overkill, just insert the value like you did the others

<td> <a href="/home/harish/Desktop/cvision/users_output_files/{{data.id}}.zip" download></a> 
Sign up to request clarification or add additional context in comments.

2 Comments

This is what I need to create as a link: href="/home/harish/Desktop/cvision/users_output_files/'{{data.id}}'/'{{data.id}}'.zip'" But it didn't work
That's fine, just remove the single quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.