Reverse for 'album_details' with arguments '('',)' not found. 1 pattern(s) tried: ['client/user/(?P<pk>[0-9]+)/$']

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

def index(request):
    if request.user.is_authenticated:
        user = request.user
        username =
        album = Album.objects.filter(owner_id=username)
        contexts = {
            'album': album,
            'user': user
        return render(request, 'client/index.html', contexts)
        return render(request, 'client/login.html')


{% if album %}
        <h2> Hi, {{ user.first_name }}. You have some photos to choose from.
            Click <a href="
                {% url 'client:album_details' %}">here</a> </div>

    {% else %}
            Hi, {{ user.first_name }}. You don't have any photos uploaded yet.</h2>
            Wanna book me ? Click <a href="{% url 'client:bookme' %}">here</a> </div>
    {% endif %}

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 is :

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 in index.html as follow :

<div>Click <a href="{% url 'client:album_details' 1 %}">here</a></div>

it works but with or or even album_id, it doesn’t work

I’ve found something, when I tried to print the id in the html code as this :
<div> Album id is : <a href="#">{{ }}</a> </div>

So I guess I can’t have the id like this, even though I try, I have the same result.

Your context contains album, which is a queryset, not a single album. (It could be multiple albums)

Your template is trying to get the id attribute of an album, except album isn’t an Album. It’s a queryset referring to (possibly) many Album.

You either need to iterate through album to generate this link for each one, or else select which album to use from the queryset.

Thank you so much, that resolved my problems and all that followed since I know that now. I used album[0].id and made sure to use some logic in case album is empty. Thanks again !!!