NoReverseMatch:反向为“已删除",未找到任何参数.-Django [英] NoReverseMatch: Reverse for 'deleted' with no arguments not found. - Django

查看:41
本文介绍了NoReverseMatch:反向为“已删除",未找到任何参数.-Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Django的新面孔,因此请考虑我的问题是否是愚蠢的.所以我一直在练习Django,目前正在制作CRUD,但是我遇到了NoReverseMatch的问题,我在stackoverflow中经历了答案,但仍然找不到错误的地方.你们能帮我一下吗?实际上,它在工作,当我重置数据库时,它以某种方式出错,也许是我搬了东西,或者做了我所做的任何不幸的事情.我已经去了三个小时了.只是这个错误.所以请帮助我:

I'm a new face to Django so please be considerate to if ever my problem is something stupid. So I have been practicing Django, and currently making a CRUD, however I've run into problems with tegards to NoReverseMatch, I went through answers in stackoverflow but still I couldn't find where I went wrong. Can you help me a bit guys? Actually it was working, when I resetted the DB, somehow it had the error, maybe i moved something or whatever unlucky thing i did. I've been at it for 3 hours actually. Just this error. So please help me:

追溯表明NoReverseMatch在以下URL上:

The traceback says that the NoReverseMatch is on the following url:

<a href="{%url 'deleted'%}">Delete</a>

我与urls.py中的以下内容进行了适当的合作并与之建立联系.

which I properly partnered and connected with the following in my urls.py.

url(r'^delete/(?P<pk>\d+)/', Delete.as_view(), name="deleted"),

这是代码的要点:

deleteupdate/urls.py (删除和更新来自导入到文件的模型)

deleteupdate/urls.py (Delete and Update are from models imported to the file)

urlpatterns = [

    url(r'^', views.list, name='list'),

    url(r'^delete/(?P<pk>\d+)/', Delete.as_view(), name="deleted"),

    url(r'^update/(?P<pk>\d+)/', Update.as_view(), name="updated"),

    url(r'^(?P<student_id>)/', views.detail, name='detail'),

]

main/urls.py

urlpatterns = [
    url(r'^$', include('index.urls')),
    url(r'^admin/', admin.site.urls),
    url(r'^list/', include('deleteupdate.urls')),

]

以下是HTML:

{% if all_students %}

<ul>
    {% for user in all_users %}
    <li><a href="/list/{{ user.id }}"></a>



<button type="button">
<a href="{%url 'deleted'%}">Delete</a>
</button>


<button type="button">
<a href='{% url 'updated' %}'>Update</a>
</button>
{% endfor%}
</ul>

{% else %}
<h3>Users is empty</h3>
{% endif %}

我做错了什么?我想我已经遵循了我所能找到的所有建议,但是是的,它仍然给了我错误.任何帮助表示赞赏.非常感谢你!

What am I doing wrong? I think I have followed every advice I could find, but yeah it still gives me the error. Any help is appreciated. Thank you very much!

以下是错误:

/list/

反向表示已删除",未找到任何参数.尝试了1种模式:['list/delete/(?P \ d +)/']

Reverse for 'deleted' with no arguments not found. 1 pattern(s) tried: ['list/delete/(?P\d+)/']

推荐答案

您需要< pk> 来匹配您的网址,这样它才能匹配.我为您编辑了此部分:

You need a <pk> to go with your url so it will match. I edited this part for you:

{% for student in all_students %}
<li><a href="/list/{{ student.id }}">{{ student.first_name }} {{ student.last_name }} ({{ student.course }})</a>

<p><a class="btn btn-lg btn-success" href="{% url "delete" pk=student.id %}"role="button">Delete</a>
            <a class="btn btn-lg btn-success" href="{% url "update" pk=student.id %}" role="button">Update</a>

 </p>

{% endfor%}

这篇关于NoReverseMatch:反向为“已删除",未找到任何参数.-Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆