py2exe
py2exe

Reputation: 39

link in html do not function

python 2.7 DJANGO 1.11.14 win7

when I click the link in FWinstance_list_applied_user.html it was supposed to jump to FW_detail.html but nothing happened

url.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:

class FWDetailView(LoginRequiredMixin,generic.ListView):

     model = FW
     template_name = 'FW_detail.html'

models.py

class FW(models.Model):

    ODM_name = models.CharField(max_length=20)
    project_name = models.CharField(max_length=20)

FW_detail.html

{% block content %}

<h1>FW request information: {{ FW.ODM_name}};{{ FW.project_name}}</h1>

<p><strong>please download using this link:</strong> {{ FW.download }}</p>

{% endblock %}

FWinstance_list_applied_user.html

{% block content %}
    <h1>Applied FWs</h1>

    {% if FW_list %}
    <ul>

      {% for FWinst in FW_list %}
        {% if FWinst.is_approved %}
      <li class="{% if FWinst.is_approved %}text-danger{% endif %}">-->
        <a href="{% url 'FW-detail' FWinst.pk %}">{{FWinst.ODM_name}}</a> ({{ FWinst.project_name }})
      </li>
        {% endif %}
      {% endfor %}
    </ul>

    {% else %}
      <p>Nothing.</p>
    {% endif %}       
{% endblock %}

the image of FWinstance_list_applied_user.html, when I click the link CSR, nothing happenedenter image description here

Upvotes: 0

Views: 46

Answers (2)

Daniel Roseman
Daniel Roseman

Reputation: 599470

You haven't terminated your "my-applied" URL pattern, so it matches everything beginning with "myFWs/" - including things that that would match the detail URL. Make sure you always use a terminating $ with regex URLs.

url(r'^myFWs/$', views.LoanedFWsByUserListView.as_view(), name='my-applied'),

Upvotes: 2

Daniel Hepper
Daniel Hepper

Reputation: 29977

You are seeing this behavior because your first URL pattern is not terminated. The regular expression r'^myFWs/' also matches the URL path myFWs/123, so your FW-detail URL is never matched. You can fix that by simply appending a $ to your URL pattern.

urlpatterns += [   
    url(r'^myFWs/$', views.LoanedFWsByUserListView.as_view(), name='my-applied'),
               # ^ this was missing

Upvotes: 1

Related Questions