aphex
aphex

Reputation: 1177

Reverse for '' with arguments '(1L,)' and keyword arguments '{}' not found

I'm new to Django and faced with next problem: when I turn on the appropriate link I get next error:

NoReverseMatch at /tutorial/

Reverse for 'tutorial.views.section_tutorial' with arguments '(1L,)' and keyword arguments '{}' not found.

What am I doing wrong? and why in the args are passed "1L" instead of "1"? (when i return "1" i get same error.) I tried to change 'tutorial.views.section_tutorial' for 'section-detail' in my template but still nothing has changed. Used django 1.5.4, python 2.7; Thanks!

tutorial/view.py:

def get_xhtml(s_url):
    ...
    return result

def section_tutorial(request, section_id):
    sections = Section.objects.all()
    subsections = Subsection.objects.all()
    s_url = Section.objects.get(id=section_id).content
    result = get_xhtml(s_url) 
    return render(request, 'tutorial/section.html', {'sections': sections,
                                                     'subsections': subsections,
                                                     'result': result})

tutorial/urls.py:

from django.conf.urls import patterns, url
import views

urlpatterns = patterns('',
    url(r'^$', views.main_tutorial, name='tutorial'),
    url(r'^(?P<section_id>\d+)/$', views.section_tutorial, name='section-detail'),
    url(r'^(?P<section_id>\d+)/(?P<subsection_id>\d+)/$', views.subsection_tutorial, name='subsection-detail'),
)

urls.py:

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^tutorial/$', include('apps.tutorial.urls')),
)

main.html:

{% extends "index.html" %} 
{% block content %}
<div class="span2" data-spy="affix">
  <ul id="menu">
    {% for section in sections %}
    <li>
      <a href="{% url 'tutorial.views.section_tutorial' section.id %}">{{ section.name }}</a>
      <ul>
        {% for subsection in subsections%}
        {% if subsection.section == section.id %}
        <li><a href=#>{{ subsection.name }}</a></li>
        {% endif %}
        {% endfor %}
      </ul>
      {% endfor %}
    </li>
  </ul>
</div>
<div class="span9">
    <div class="well">
    {% autoescape off%}
    {{ result }}
    {% endautoescape %}

</div>
</div>

{% endblock %}

Upvotes: 3

Views: 1311

Answers (1)

Aamir Rind
Aamir Rind

Reputation: 39649

You don't need $ identifier in url regex in your main urls file when including app urls:

url(r'^tutorial/$', include('apps.tutorial.urls')),

should be:

url(r'^tutorial/', include('apps.tutorial.urls')),

Upvotes: 4

Related Questions