python - 在 python 代码中出现“NoReverseMatch”错误
问题描述
尝试删除创建的主题时,在我的 python 代码中出现此错误。 以下是 url、视图和模板片段。
path('delete_topic/<int:topic_id>/', views.delete_topic, name='delete_topic')
def delete_topic(request, topic_id):
topic = Topic.objects.get(id=topic_id)
if request.method == 'POST':
topic.delete()`enter code here`
return redirect('online_diaries:topics', topic_id=topic.id)
context = {'topic': topic}
return render(request, 'online_diaries/delete_topic.html', context)
{% extends "online_diaries/base.html" %}
{% block content %}
<p>Are you sure to delete the topic <b><u>{{ topic }}?</b></u></p>
<form method="POST" action = "{% url 'online_diaries:delete_topic' topic.id %}">
{% csrf_token %}
<a href="{% url 'online_diaries:topics' %}" class="btn btn-outline-success btn-sm">cancel</a>
<input type = "submit" name = "Confirm" class="btn btn-secondary btn-sm">
</form>
{% endblock content %}
解决方案
推荐阅读
- ios - ios如何判断Family Sharing团购
- powershell - 使用 PowerShell 将可用性集添加到 Azure 负载均衡器的后端池
- php - 邮件配置错误
- python - AWS API Gateway Lambda 错误正则表达式
- codeigniter - 我无法使用 Codeigniter for REST API 将多行插入 mysql
- linux - NTLM 身份验证无效字符
- terraform - 在 terraform 中,如何使用地图列表列表?
- java - 如何从 Firebase 数据库中获取这些数据
- opengl - 子进程从父进程继承 nvidia 配置文件
- javascript - 用值替换断线