Django 中的 href 供来宾访问者访问用户个人资料页面
href in Django for guest visitor to a user profile page
我有
url(r'^profile/(?P<userid>\d+)', views.profile, name='profile'),
在urls.py
我有
def profile(request, userid):
要让来宾访问者能够查看用户个人资料页面,我应该为按钮的 href 提供什么?
href="/accounts/profile/<userid>"
或
href="{% url 'users:profile' user.id %}"
以上两个我都无法正常工作。
谢谢。
我实际上 运行 几天前就进入了这个问题。
{% url 'users:profile' user.id as profile_link %}
<a href="{{ profile_link }}">Profile</a>
另外,为了将来,您的示例不会在 url 的命名空间和名称之间包含单引号。你应该有 {% url 'users:namehere' %}
,而不是 {% url users:namehere %}
我有
url(r'^profile/(?P<userid>\d+)', views.profile, name='profile'),
在urls.py
我有
def profile(request, userid):
要让来宾访问者能够查看用户个人资料页面,我应该为按钮的 href 提供什么?
href="/accounts/profile/<userid>"
或
href="{% url 'users:profile' user.id %}"
以上两个我都无法正常工作。 谢谢。
我实际上 运行 几天前就进入了这个问题。
{% url 'users:profile' user.id as profile_link %}
<a href="{{ profile_link }}">Profile</a>
另外,为了将来,您的示例不会在 url 的命名空间和名称之间包含单引号。你应该有 {% url 'users:namehere' %}
,而不是 {% url users:namehere %}