Django 1.8 template's URL tag TypeError
Question: I am trying to learn how to use the Django template's URL tag to make my code
more generic, but I am having some exception being raised.

    
    
    Exception Type:     TypeError
    Exception Value:    argument to reversed() must be a sequence
    

Here is my global urls.py

    
    
    from django.conf.urls import include, url
    from django.contrib import admin
    
    urlpatterns = [
        url(r'^admin/', include(admin.site.urls)),
        url(r'^polls/', include('polls.urls'))
    ]
    

Here is my app urls.py

    
    
    from django.conf.urls import url
    from . import views
    
    urlpatterns = {
        url(r'^$', views.index, name='index'),
        url(r'^(?P<id>[0-9]+)/$', views.detail, name='detail'),
        url(r'^(?P<id>[0-9]+)/results/$', views.results, name='results'),
        url(r'^(?P<id>[0-9]+)/vote/$', views.vote, name='vote')
    }
    

And here is one template where I am trying to use the feature.

    
    
    {% if latest_question_list %}
      <ul>
        {% for question in latest_question_list %}
          <li><a href="{% url 'polls:detail' question.id %}">{{ question.content }}</a></li>
        {% endfor %}
      </ul>
    {% else %}
      <p>No polls are available.</p>
    {% endif %}
    

Traceback:

    
    
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
      132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/home/polydo_s/Projects/Modeling/app/polls/views.py" in index
      11.     return render(request, 'polls/index.html', context)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/shortcuts.py" in render
      67.             template_name, context, request=request, using=using)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/template/loader.py" in render_to_string
      99.         return template.render(context, request)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/template/backends/django.py" in render
      74.         return self.template.render(context)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/template/base.py" in render
      209.                     return self._render(context)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/template/base.py" in _render
      201.         return self.nodelist.render(context)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/template/base.py" in render
      903.                 bit = self.render_node(node, context)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/template/debug.py" in render_node
      79.             return node.render(context)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/template/defaulttags.py" in render
      329.                 return nodelist.render(context)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/template/base.py" in render
      903.                 bit = self.render_node(node, context)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/template/debug.py" in render_node
      79.             return node.render(context)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/template/defaulttags.py" in render
      217.                             nodelist.append(node.render(context))
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/template/defaulttags.py" in render
      493.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/core/urlresolvers.py" in reverse
      579.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
      433.             self._populate()
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/core/urlresolvers.py" in _populate
      308.                     for name in pattern.reverse_dict:
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/core/urlresolvers.py" in reverse_dict
      338.             self._populate()
    File "/home/polydo_s/Projects/Modeling/venv/lib/python3.4/site-packages/django/core/urlresolvers.py" in _populate
      285.         for pattern in reversed(self.url_patterns):
    

I have been looking for this for hours, and I seem to follow all the
guidelines to make this work, but of course something must be wrong.


Answer: You've defined `urlpatterns` as a `set` \- `{` and `}`. You need a `list` \-
`[` and `]`.

    
    
    urlpatterns = [
        url(r'^$', views.index, name='index'),
        url(r'^(?P<id>[0-9]+)/$', views.detail, name='detail'),
        url(r'^(?P<id>[0-9]+)/results/$', views.results, name='results'),
        url(r'^(?P<id>[0-9]+)/vote/$', views.vote, name='vote')
    ]
    

