Search code examples
pythondjangodjango-templatesdjango-viewsdjango-urls

Reverse for 'todo-user' with arguments '('',)' not found. 1 pattern(s) tried


I am trying to add a user when clicking on a link but I'm getting the following error :

Reverse for 'todo-user' with arguments '('',)' not found. 1 pattern(s) tried: ['todo/(?P<todo_id>[^/]+)/$']

My views.py

def todo_user(request, todo_id):
    todo.username.add(request.user)
    todo.save()
    return render(request, '/')

Template

<a href="{% url 'todo-user' todo.id %}"></a>

Urls.py

path('validate/<todo_id>/', views.todo_user, name='todo-user),

Views.py for the template render :

def home(request, token):
            todo_instance = get_object_or_404(Todo, token=token)
            context = {
                'token': todo_instance.token,
                'name': todo_instance.name,
       }
       return render(request, '/', context)

Thanks to you guys !


Solution

  • In your template you're referring to a todo variable:

    <a href="{% url 'todo-user' todo.id %}"></a>
    

    but in your context used to render the template, no such variable is defined. Add

    'todo': todo_instance
    

    to your context. You can remove 'token' and 'name' and use {{ todo.name }} in you template instead.