Brian
Brian

Reputation: 877

href in Django for guest visitor to a user profile page

I have

url(r'^profile/(?P<userid>\d+)', views.profile, name='profile'),

in the urls.py

And I have

def profile(request, userid):

What should I have for a button's href for guest visitors to be able to view the user profile page?

href="/accounts/profile/<userid>"

or

href="{% url 'users:profile' user.id %}"

I can't get neither of the above working. Thanks.

Upvotes: 0

Views: 263

Answers (1)

Magic
Magic

Reputation: 372

I actually ran into this issue a few days ago.

{% url 'users:profile' user.id as profile_link %}
<a href="{{ profile_link }}">Profile</a>

Also for the future, your example did not include single quotes between the namespace and name of the url. You should have {% url 'users:namehere' %}, not {% url users:namehere %}

Upvotes: 1

Related Questions