Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
Django 在基于类的视图中抛出NoReverseMatch_Django - Fatal编程技术网

Django 在基于类的视图中抛出NoReverseMatch

Django 在基于类的视图中抛出NoReverseMatch,django,Django,因此,我有一个视图列出了一系列链接: class CheckpointSelectView(mixins.LoginRequiredMixin, generic.ListView): model = Checkpoint template_name = 'warden/checkpoint_select_view.html' context_object_name = 'checkpoints' 模板: <!DOCTYPE

因此,我有一个视图列出了一系列链接:

class CheckpointSelectView(mixins.LoginRequiredMixin, generic.ListView):
    model               = Checkpoint
    template_name       = 'warden/checkpoint_select_view.html'
    context_object_name = 'checkpoints'
模板:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
{% block content %}
    <ul>
        {% for checkpoint in checkpoints %}
            <li><a href="{% url 'checkpoint' checkpoint_name=checkpoint.name %}">{{ checkpoint.name }}</a></li>
        {% endfor %}
    </ul>
{% endblock %}
</body>
</html>

标题
{%block content%}
    {检查点%中的检查点的百分比}
  • {%endfor%}
{%endblock%}
和一些URL:

urlpatterns = [
    url(r'^$', CheckpointSelectView.as_view(), name='checkpoint_selection'),
    url(r'^(?P<checkpoint_name>\w+-{0,1}\w+)/$', CheckpointWatchView.as_view(), name='checkpoint'),
]
urlpatterns=[
url(r'^$',CheckpointSelectView.as_view(),name='checkpoint_selection'),
url(r'^(?P\w+-{0,1}\w+/$”,CheckpointWatchView.as_view(),name='checkpoint'),
]
当我导航到该视图时,Django会引发NoReverseMatch异常,但如果我这样更改模板:

{% block content %}
    <ul>
        {% for checkpoint in checkpoints %}
            <li><a href="{{ checkpoint.name }}">{{ checkpoint.name }}</a></li>
        {% endfor %}
    </ul>
{% endblock %}
{%block content%}
    {检查点%中的检查点的百分比}
  • {%endfor%}
{%endblock%}
它起作用了

我是否使用了错误的url标记?非常感谢您的帮助

回溯:

NoReverseMatch at /en/warden/

Reverse for 'checkpoint' with arguments '()' and keyword arguments '{'checkpoint_name': 'start'}' not found. 1 pattern(s) tried: ['(ro|en)/warden/(?P<checkpoint_name>\\w+-{0,1}\\w+)/$']

Request Method:     GET
Request URL:    http://127.0.0.1:8000/en/warden/
Django Version:     1.10.7
Exception Type:     NoReverseMatch
Exception Value:    

Reverse for 'checkpoint' with arguments '()' and keyword arguments '{'checkpoint_name': 'start'}' not found. 1 pattern(s) tried: ['(ro|en)/warden/(?P<checkpoint_name>\\w+-{0,1}\\w+)/$']

Exception Location:     /home/jotun/workspace/.virtualenvs/AESH/lib/python3.6/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 392
Python Executable:  /home/jotun/workspace/.virtualenvs/AESH/bin/python
Python Version:     3.6.2
NoReverseMatch at/en/warden/
未找到参数为“()”且关键字参数为“{'checkpoint_name':'start'}”的“checkpoint”的反转。尝试了1个模式:['(ro|en)/warden/(?P\\w+-{0,1}\\w+/$)]
请求方法:获取
请求URL:http://127.0.0.1:8000/en/warden/
Django版本:1.10.7
异常类型:NoReverseMatch
异常值:
未找到参数为“()”且关键字参数为“{'checkpoint_name':'start'}”的“checkpoint”的反转。尝试了1个模式:['(ro|en)/warden/(?P\\w+-{0,1}\\w+/$)]
异常位置:/home/jotun/workspace/.virtualenvs/AESH/lib/python3.6/site-packages/django/url/resolvers.py in_reverse_,带前缀,第392行
Python可执行文件:/home/jotun/workspace/.virtualenvs/AESH/bin/Python
Python版本:3.6.2

请显示完整的异常。好的,忘了这一点,编辑。因此,在模式的开头有一个语言参数,有两个选项。
reverse
如何知道使用哪一个?你应该把它作为一个捕获参数(比如
checkpoint\u name
)并将其传递进来。这样做了,我忽略了它,因为它来自另一个URL.py,谢谢!!请显示完整的异常。好的,忘了这一点,Edited所以在模式的开头有一个语言参数,有两个选项。
reverse
如何知道使用哪一个?你应该把它作为一个捕获参数(比如
checkpoint\u name
)并将其传递进来。这样做了,我忽略了它,因为它来自另一个URL.py,谢谢!!