get absolute url method on the model

Solutions on MaxInterview for get absolute url method on the model by the best coders in the world

showing results for - "get absolute url method on the model"
Abrianna
24 Apr 2019
1First of all, when it comes to web development you really want to avoid hard coding paths in your templates. The reason for this is that paths might change, and it will be a hassle to go through all your HTML and templates to find every single URL or path and update it manually. It makes your code much harder to maintain.
2
3The solution to this is to define functions that return the URL instead. This is where get_absolute_url() comes into the picture.
4
5<!-- Bad -->
6<a href="/language/category/product/{{product.pk}}">Link</a>
7
8<!-- Good -->
9<a href="{{product.get_absolute_url}}">Link</a>
10
Lucas
14 Nov 2019
1First of all, when it comes to web development you really want to avoid hard coding paths in your templates. The reason for this is that paths might change, and it will be a hassle to go through all your HTML and templates to find every single URL or path and update it manually. It makes your code much harder to maintain.
2
3The solution to this is to define functions that return the URL instead. This is where get_absolute_url() comes into the picture.