Hello everyone. I have an app where users can see album and photos, but they have to be authenticated to be able to do that. In views.py
@login_required(login_url='login')
def index(request):
if request.user.is_authenticated:
user = request.user
username = request.user.pk
album = Album.objects.filter(owner_id=username)
contexts = {
'album': album,
'user': user
}
return render(request, 'client/index.html', contexts)
else:
return render(request, 'client/login.html')
index.html
{% if album %}
<h2> Hi, {{ user.first_name }}. You have some photos to choose from.
</h2>
<div>
Click <a href="
{% url 'client:album_details' album.id %}">here</a> </div>
{% else %}
<h2>
Hi, {{ user.first_name }}. You don't have any photos uploaded yet.</h2>
<div>
Wanna book me ? Click <a href="{% url 'client:bookme' %}">here</a> </div>
{% endif %}
urls.py
url(r'^user/(?P<pk>[0-9]+)/$', user_album_details, name='album_details'),
last but not least, the call to the user_album_details functions in views.py is :
@login_required(login_url='login')
def user_album_details(request, pk):
album = get_object_or_404(Album, id=pk)
return render(request, 'client/photo_details.html', {'album': album})
The error :
NoReverseMatch at /client/user/
Reverse for 'album_details' with arguments '('',)' not found. 1 pattern(s) tried: ['client/user/(?P<pk>[0-9]+)/$']
Partial solution:
if I replace album.id in index.html as follow :
<div>Click <a href="{% url 'client:album_details' 1 %}">here</a></div>
it works but with album.id or album.pk or even album_id, it doesn’t work