52👍
✅
Why create a new template tag/filter if the feature is in core?
Look the samples at: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url
{% url 'path.to.view' arg arg2 as the_url %}
<a href="{{ the_url }}">I'm linking to {{ the_url }}</a>
and
{% url 'path.to.view' as the_url %}
{% if the_url %}
<a href="{{ the_url }}">Link to optional stuff</a>
{% endif %}
-4👍
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.
- Django: WSGIRequest' object has no attribute 'user' on some pages?
- Create a canonical "parent" product in Django Oscar programmatically
- How to have a link in label of a form field
- How to customize django rest auth password reset email content/template
Source:stackexchange.com