Changes between Version 10 and Version 11 of ReplacingGetAbsoluteUrl
- Timestamp:
- Sep 22, 2009, 11:57:13 AM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ReplacingGetAbsoluteUrl
v10 v11 10 10 == The problem == 11 11 12 It's often useful for a model to "know" it 's URL. This is especially true for sites that follow RESTful principles, where any entity within the site should have one and only one canonical URL.12 It's often useful for a model to "know" its URL. This is especially true for sites that follow RESTful principles, where any entity within the site should have one and only one canonical URL. 13 13 14 14 It's also useful to keep URL logic in the same place as much as possible. Django's {% url %} template tag and reverse() function solve a slightly different problem - they resolve URLs for view functions, not for individual model objects, and treat the URLconf as the single point of truth for URLs. {% url myapp.views.profile user.id %} isn't as pragmatic as {{ user.get_absolute_url }}, since if we change the profile-view to take a username instead of a user ID in the URL we'll have to go back and update all of our templates.