我在django中做了一個應用程序,並且我完全熟悉Python和框架django。在django中構建url
我的問題是我無法弄清楚如何得到這個網址:
project/2/ticket/1
林在project/2
並得到了我的模板鏈接到project/2/ticket/1
的鏈接。 我得到的錯誤是NoReverseMatch at /project/1
和使用的代碼IM是:
url.py
urlpatterns = patterns('',
# Project urls below
url(r'^project/(?P<project_id>\d+)$', 'project_manager.views.project_list', name='project_list_with_ticket'),
url(r'^project/(?P<project_id>\d+)/ticket/(?P<ticket_id>\d+)$', 'project_manager.views.ticket_list', name='ticket_list'),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
views.py
def ticket_list(request, ticket_id = None):
if ticket_id:
tickets = get_list_or_404(Ticket.objects.filter(id = ticket_id))
return render(request, 'tickets/details.html', {"tickets" : tickets })
else:
return render(request, 'projects/list.html', {'projects' : projects })
我的模板
{% for ticket in tickets %}
<div class="tickets">
<a href="{% url ticket_list ticket.id %}">{{ ticket }}</a>
</div>
{% endfor %}
編輯 - 它說沒有ticket_list,但也有?
謝謝,作品完美! :D我儘快做出這個安慰 – Rovdjuret 2013-02-19 17:08:50