Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 与#x27相反';带参数';(1L,)和"x27 ;;和关键字参数';{}';找不到_Python_Django_Reverse - Fatal编程技术网

Python 与#x27相反';带参数';(1L,)和"x27 ;;和关键字参数';{}';找不到

Python 与#x27相反';带参数';(1L,)和"x27 ;;和关键字参数';{}';找不到,python,django,reverse,Python,Django,Reverse,我是Django的新手,面临着下一个问题:当我打开适当的链接时,我会遇到下一个错误: NoReverseMatch at/tutorial/ 找不到参数为“(1L,)”且关键字参数为“{}”的“tutorial.views.section_tutorial”的相反版本。 我做错了什么?为什么在参数中传递的是“1L”而不是“1”?(当我返回“1”时,我得到了相同的错误。)我试图更改模板中'section-detail'的'tutorial.views.section\u tutorial',但仍然

我是Django的新手,面临着下一个问题:当我打开适当的链接时,我会遇到下一个错误:

NoReverseMatch at/tutorial/

找不到参数为“(1L,)”且关键字参数为“{}”的“tutorial.views.section_tutorial”的相反版本。

我做错了什么?为什么在参数中传递的是“1L”而不是“1”?(当我返回“1”时,我得到了相同的错误。)我试图更改模板中
'section-detail'
'tutorial.views.section\u tutorial'
,但仍然没有任何更改。使用django 1.5.4、python 2.7;谢谢

教程/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})
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'),
)
urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^tutorial/$', include('apps.tutorial.urls')),
)
教程/url.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})
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'),
)
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 %}
{%extends“index.html”%}
{%block content%}
    {第%节中的第%节}
    • {%子节中的子节%} {%if subsection.section==section.id%}
    • {%endif%} {%endfor%}
    {%endfor%}
{%autoescape off%} {{result}} {%endautoescape%} {%endblock%}
当包含应用程序url时,在主url文件的url regex中不需要
$
标识符:

url(r'^tutorial/$', include('apps.tutorial.urls')),
应该是:

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

我花了30分钟想弄明白,这救了我一命!那么像这样的正则表达式到底是做什么的呢<代码>url(r'^',包括('list.url'),