3
我是新來的Django和麪臨的下一個問題:當我打開相應的鏈接,我得到一個錯誤:反向爲「」與參數「(1L)」和關鍵字參數「{}」未找到
NoReverseMatch at /tutorial/
Reverse for 'tutorial.views.section_tutorial' with arguments '(1L,)' and keyword arguments '{}' not found.
我在做什麼錯?爲什麼在參數中通過「1L」而不是「1」? (當我返回「1」時,我得到同樣的錯誤。)我嘗試在我的模板中更改'tutorial.views.section_tutorial'
爲'section-detail'
,但仍然沒有任何變化。使用django 1.5.4,python 2.7;謝謝!
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 %}
這樣一個愚蠢的錯誤。非常感謝! – aphex
花了30分鐘試圖找出它,這才救了我!這樣的正則表達式到底是什麼呢? 'url(r'^',include('list.urls')),' – MadPhysicist