我是新來的Django並不能似乎找到了解決我的問題NoReverseMatch錯誤的Django 1.10
我收到以下錯誤
Reverse for 'todo_list' with arguments '()' and keyword arguments
'{'cid': 1}' not found. 1 pattern(s) tried: ['todo/(?P<cid>)/']
1 {% extends "base.html" %}
2 {% block nav_title %} Company Batches {% endblock nav_title %}
3 {% block content %}
4 <div class="jumbotron">
5
6 {% for obj in object_list %}
7 <a href={% url 'todo_list' cid=obj.company.id%} class="href-nostyle">
8 <div class="container">
9 <div class="jumbotron" style="background:white">
10 <div class="text-center">
11 <h1>{{ obj.company }}<br>
12 <small>{{ obj.job }}</small>
13 </h1>
14 </div>
15 </div>
16 </div>
17 </a>
此模板位於一個名爲應用company_batches和我試圖用一個href
我的網址標籤導航用戶的待辦事項程序是
{% url 'todo_list' cid=obj.company.id%}
我的主urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', home, name='home'),
url(r'^batches/', include('company_batches.urls')),
url(r'^todo/', include('todo.urls'), name='todo')
]
待辦事項/ urls.py
urlpatterns = [
url(r'^$', ToDoCreateView.as_view(), name='todo_create'),
url(r'^(?P<cid>)/', ToDoListView.as_view(), name='todo_list'),
]
相關views.py
class ToDoListView(ListView,):
template_name = 'todo/todo_list.html'
def get_context_data(self, *args, **kwargs):
context = super(ToDoListView, self).get_context_data(*args, **kwargs)
return context
def get_queryset(self, cid):
return ToDoList.objects.filter(company=self.cid)
我找不出我在做什麼錯誤的,一些指導將不勝感激
在正則表達式你'cid'捕獲組是空的。 –