0

I am new to Django and cant seem to find a solution to my problem

I get the following error

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>

This template is located in an app named company_batches and I am attempting to navigate a user to the todo app using an href

my url tag is

{% url 'todo_list' cid=obj.company.id%}

my main 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')
]

todo/urls.py

urlpatterns = [
    url(r'^$', ToDoCreateView.as_view(), name='todo_create'),
    url(r'^(?P<cid>)/', ToDoListView.as_view(), name='todo_list'),
    ]

the relevant 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)

I cant figure out what I'm doing wrong, some guidance would be much appreciated

Eitan Seri-Levi
  • 341
  • 3
  • 17

2 Answers2

2

Your regex is broken; it doesn't have any characters to match on. It looks like you want to capture a numeric PK, do it should be:

r'^(?P<cid>\d+)/
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
2

There are a few things to notice here.

Regular expression, probably the actual issue here
Capturing the cid in your url regex does not contain a proper capturing group. Since it's an ID, you should only capture digits with \d+

url(r'^(?P<cid>\d+)/', ToDoListView.as_view(), name='todo_list'),

Closing url regex
The current url does not contain a closing sign. If the url actually ends after the /app/<id>/, you should most likely close the regular expression with the dollar sign $.

url(r'^(?P<cid>\d+)/$', ToDoListView.as_view(), name='todo_list'),

Namespace usage
You are using a name while including the todo app urls. To use the namespace properly, you should drop the name in the todo/ url and add the namespace to the include.

url(r'^todo/', include('todo.urls', namespace='todo'))

Now in your template you can use the namespace

{% url 'todo:todo_list' cid=obj.company.id %}
Nrzonline
  • 1,600
  • 2
  • 18
  • 37