Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.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 删除视图中的NoReverse匹配_Python_Django - Fatal编程技术网

Python 删除视图中的NoReverse匹配

Python 删除视图中的NoReverse匹配,python,django,Python,Django,上周我开始使用Python和Django编写代码,现在我开始对此感到绝望。 我必须处理待办事项列表,并希望通过单击任务旁边的按钮来删除待办事项。 现在我总是得到一份工作 NoReverseMatch at/delete/1 错误:( delete_confirm.html: {% extends "base_page.html" %} {% block title %}Confirm Todo delete{% endblock %} {% block content %} <form

上周我开始使用Python和Django编写代码,现在我开始对此感到绝望。 我必须处理待办事项列表,并希望通过单击任务旁边的按钮来删除待办事项。 现在我总是得到一份工作

NoReverseMatch at/delete/1

错误:(

delete_confirm.html:

{% extends "base_page.html" %}

{% block title %}Confirm Todo delete{% endblock %}

{% block content %}
<form action="" method="post">{% csrf_token %}
    <p>Are you sure you want to delete "{{ object }}"?</p>
    <input type="submit" value="Confirm" />
</form>

{% endblock %}
index.html的有趣部分是:

<!--Table content-->
            {% for todo in object_list %}
            <tr>
              <td class="text-left">{{todo.title}}</td>
              <td> {{todo.deadline}}</td>
              <td>
                <div class="progress">
                  <div class="progress-bar" role="progressbar" aria-valuenow="{{todo.progress}}" aria-valuemin="0" aria-valuemax="100" style="width: {{todo.progress}}%">
                    {{todo.progress}}%
                  </div>
                </div>
              </td>
              <td >
                <div class="btn-group">
                  <a href="edit/{{todo.id}}" role="button" class="btn btn-default">Edit</a>
                  <a href="delete/{{todo.id}}" role="button" class="btn btn-default">Delete</a>
                  <button class="btn btn-default" data-toggle="tooltip" title="Done?" data-placement="right"><span class="glyphicon glyphicon-check"></button>
                </div>
              </td>
          {% endfor %}

{对象\列表%中todo的百分比}
{{todo.title}
{{todo.截止日期}
{{todo.progress}}}%
{%endfor%}

如果你们中的一些人能帮助一个新手,那就太好了:)

问题在于删除视图中的这一行

class DeleteView(DeleteView):
    ...
    success_url = reverse_lazy('/')
您可以提供url:

success_url = '/'
或者使用
reverse\u lazy
和要反转的url名称:

success_url = reverse_lazy('index')

问题是删除视图中的这一行

class DeleteView(DeleteView):
    ...
    success_url = reverse_lazy('/')
您可以提供url:

success_url = '/'
或者使用
reverse\u lazy
和要反转的url名称:

success_url = reverse_lazy('index')

问题是删除视图中的这一行

class DeleteView(DeleteView):
    ...
    success_url = reverse_lazy('/')
您可以提供url:

success_url = '/'
或者使用
reverse\u lazy
和要反转的url名称:

success_url = reverse_lazy('index')

问题是删除视图中的这一行

class DeleteView(DeleteView):
    ...
    success_url = reverse_lazy('/')
您可以提供url:

success_url = '/'
或者使用
reverse\u lazy
和要反转的url名称:

success_url = reverse_lazy('index')


对于将来的问题,请提供完整的回溯,它将包含有用的信息,如错误发生的行。作为旁白,最好使用标记,例如
{%url'todo_edit'todo.id%}
{%url'todo_delete'todo.id%}
而不是硬编码url和
编辑/{{{todo.id}
delete/{{todo.id}}
在模板中。如果您不介意,请使用给出的完整错误回溯更新您的问题。对于未来的问题,请提供完整回溯,它将包含有用的信息,如错误发生的行。另外,最好使用标记,例如
{%url'todo_edit'todo.id%}
{%url'todo_delete'todo.id%}
而不是硬编码url和
编辑/{{{todo.id}
删除/{{todo.id}
在您的模板中。如果您不介意,请使用给出的完整错误回溯更新您的问题。对于以后的问题,请提供完整的回溯,它将包含有用的信息,如错误发生的行。另外,最好使用标记,例如
{%url'todo_edit'todo.id%
{%url'todo_delete'todo.id%}
而不是硬编码url和
edit/{{{todo.id}
delete/{{todo.id}
在您的模板中。如果您不介意,请使用给出的完整错误回溯更新您的问题。对于以后的问题,请提供完整的回溯,它将包含有用的信息,如错误发生的行。另外,最好使用标记,例如
{%url'todo_edit'todo.id%
{%url'todo_delete'todo.id%}
而不是硬编码url和
edit/{{{todo.id}
delete/{{todo.id}
在你的模板中。如果你不介意的话,请用给出的完整错误回溯更新你的问题。很好,它可以工作!:)但是你能向我解释一下错误吗?我经常收到错误,但我没有找到任何网站可以轻松解释
reverse\u lazy
使用url模式的名称,例如
index
,并返回url它还可以为url获取可选参数。如果Django找不到匹配的url,它会引发一个
NoReverseMatch
异常。之所以会出现这种情况,是因为您使用
reverse\u lazy
'/'
而不是
'index'
。感谢您提供了这些有用的答案:)非常好,它可以工作s!:)但是你能给我解释一下这个错误吗?我经常收到,但是我没有找到任何网站可以解释这个错误。easy
reverse\u lazy
使用url模式的名称,例如
index
,并返回与之匹配的url,例如
“/”
。它还可以为url提供可选参数。如果Django找不到与之匹配的url,则tches,它引发了一个
NoReverseMatch
异常。之所以出现这种情况,是因为您使用
reverse\u lazy
而不是
'index'
。感谢您提供了这些有用的答案:)非常好,它可以工作!:)但是您能向我解释一下错误吗?我经常看到它,但我没有找到任何网站可以轻松解释e> reverse_lazy获取url模式的名称,例如
索引
,并返回与之匹配的url,例如
'/'
。它还可以获取url的可选参数。如果Django找不到匹配的url,则会引发
NoReverseMatch
异常。之所以出现这种情况,是因为您在
中使用了
reverse_lazy
“/”
而不是
“index”
。谢谢你提供了这些有用的答案:)很好,它可以工作!:)但是你能给我解释一下错误吗?我经常收到,但我没有找到任何网站可以轻松解释
reverse\u lazy
使用url模式的名称,例如
index
,并返回与之匹配的url,例如e> “/”。它还可以为url获取可选参数。如果Django找不到匹配的url,它会引发一个
NoReverseMatch
异常。之所以会出现这种情况,是因为您使用了
reverse\u lazy
而不是
'index'
。感谢您提供了这些有用的答案:)