py2exe
py2exe

Reputation: 39

NoReverseMatch in Django:Reverse for ....l' with arguments '('',)' not found. 1 pattern(s) tried:

Django 2.0 python 3.7 win7

urls.py

urlpatterns += [    
    url(r'^myFWs/', views.LoanedFWsByUserListView.as_view(), name='my- 
    applied'),
    url(r'^myFWs/(?P<pk>[0-9]+)$', views.FWDetailView.as_view(), name='FW-detail'),
]

views.py

from .models import FW

class LoanedFWsByUserListView(LoginRequiredMixin,generic.ListView):


   model = FW
   paginate_by = 10
   template_name = 'catalog/FWinstance_list_applied_user.html'
   def get(self, request):
       form = FWForm()
       FW_list = FW.objects.all()
       return render_to_response(self.template_name, locals())

FWinstance_list_applied_user.html:

{% block content %}
        <h1>Applied FWs</h1>
        <p>FW_list:</p>{{FW_list}}
        {% if FW_list %}
        <ul>
        {% for FWinst in FW_list %}
        <li class="{% if FWinst.is_approved %}text-danger{% endif %}">-->
        <a href="{% url 'FW-detail' FWinst.FW.pk %}">{{FWinst.ODM_name}}</a> ({{ 
        FWinst.project_name }})
        </li>
        {% endfor %}
        </ul>
        {% else %}
        <p>Nothing.</p>
        {% endif %}       
        {% endblock %}

The error is :

NoReverseMatch at /catalog/myFWs/
Reverse for 'FW-detail' with arguments '('',)' not found. 1 pattern(s) tried: ['catalog/myFWs/(?P<pk>[0-9]+)$']

Upvotes: 1

Views: 103

Answers (1)

Selcuk
Selcuk

Reputation: 59228

Obviously FWinst.FW.pk returns an empty string and your regex fails to match. Just change the following tag:

{% url 'FW-detail' FWinst.FW.pk %}

to

{% url 'FW-detail' FWinst.pk %}

Upvotes: 1

Related Questions