Assign Value of Named URL to a Variable in Django Templates

后端 未结 2 1688
刺人心
刺人心 2021-02-18 23:38

In my Django template I need to assign the value of a names url into a variable within a with block so I can use it in multiple places.

I need to achieve something like

2条回答
  •  醉话见心
    2021-02-18 23:58

    I think you'll have to either create your own template tag to manage this problem or create the necessary data in the view and pass it in to the template.

    Depending on exactly what you're trying to do maybe including another template and sending in your defined variable could do it, but I doubt it.

    The thinking behind Djangos templating system is to make it so there isn't very much logic in the templates. And thus it's back to either preparing the data you need for output in the view or making a template tag.

提交回复
热议问题