【发布时间】:2010-12-20 13:21:33
【问题描述】:
我正在我的 django 应用程序中构建一个导航菜单,其中一个选项是“我的帐户”。我为用户设置了不同的角色,但为了让他们都能查看他们的个人资料,我使用了一个通用 URL,例如 http://mysite/user//profile。
使用模板构建此 url 的 Django 最佳实践是什么?
是不是很简单:
<a href="/user/{{ user.id }}/profile">My Account</a>
或者是:
<a href="{{ url something something }}">My Account</a>
不完全确定使用 url 模板标签的适当语法是什么。这是我的 URLconf 的样子:
(r'^user/(?P<user_id>\d+)/profile/$', user_profile)
我最好的选择是什么?
【问题讨论】: