views:

34

answers:

3

How to call controller function from template in Django instead of hardcoding URIs?

+1  A: 

I guess You mean "link to it".

This can be done via {% url %} tag, see docs

If Your intent is to call view function directly, this is not possible by design - templates should not know about views, it's a separate layer.

Almad
A: 

How to call controller function from template

Not sure what you mean here. If you mean to provide an an HTML link to it see the second part of my answer below.

instead of hardcoding URIs?

In case you haven't already, use the {% url %} tag. Use this in conjunction with named URLs in your url config.

Manoj Govindan
A: 

If you mean adding URL to the resulting HTML, then either use {% url %} tag as others, or get used to writing and using model_instance.get_absolute_url(). Personally I'm using the latter whenever possible, adding also custom "URL functions" like get_delete_url() etc.

Tomasz Zielinski