I have:
path('new/', views.new, name='new_without_arg'),
path('new/<str:arg>', views.new_with_arg, name='new_with_arg')
in my urls.py and when I have 'new_with_arg' in a template:
<a href="{% url 'new_with_arg' subject %}">New Subject</a>
I get:
Reverse for 'new_with_arg' with arguments '('',)' not found. 1 pattern(s) tried: ['new/(?P[^/]+)$']
My views.py is:
def new(request):
return render(request, 'notes/new.html')
def new_with_arg(request, arg):
if(arg == 'task'):
return render(request, 'notes/new_task.html')
elif(arg == 'room'):
return render(request, 'notes/new_room.html')
elif(arg == 'subject'):
return render(request, 'notes/new_subject.html')
else:
return HttpResponseRedirect(reverse('new_without_arg'))
I got it, it had to be:
<a href="{% url 'new_with_arg' 'subject' %}">New Subject</a>