Reverse for '**' with arguments '('',)' not found. 1 pattern(s) tried(topic_id与topic.id)
最近在学习《python 从入门到精通》第19章,进行环境搭建时出现了一个错误,python 版本:3.7.4,django 版本:2.2.5
NoReverseMatch at /new_entry/2
Reverse for 'topic' with arguments '('',)' not found. 1 pattern(s) tried: ['topic/(?P<topic_id>[0-9]+)$'],截图如下:
错误里显示找不到带有"(")"参数的topic,尝试使用'topic/<int:topic_id>'来匹配。虽然图中显示报错在base.html,但此错误还是出现在new_entry.html,其源码如下:
{% extends "learning_logs/base.html" %}
{%block content %}
<p><a href="{%url 'learning_logs:topic' topic_id %}"> {{ topic }} </a></p>
<p>Add a new entry:</p>
<form action ="{%url 'learning_logs:new_entry' topic.id %}" method="post">
{% csrf_token %}
{{ form.as_p }}
<button name='submit'>add entry </button>
</form>
{% endblock content %}
其中第4行使用到了topic_id,第8行使用的topic.id(已标红),使用topic_id的视图分别是topic和new_entry视图,topic_id是两个视图里面的形参。出现此错误的原因是一是在new_entry视图里未传送topic_id,导致topic_id被认为是无效参数,二是使用topic.id自动识别ID参数(在topic视图和new_entry视图里,topic=Topic.objects.get(id=topic_id))。所以解决方法有两个
(1)修改new_entry视图,将topic_id参数传过来,即将context={'topic':topic,'form':form}修改为context={'topic':topic,'form':form,'topic_id':topic_id},render函数保持不变
(2)修改第4行topic_id为topic.id 。此是书中的写法
Reverse for '**' with arguments '('',)' not found. 1 pattern(s) tried(topic_id与topic.id)相关推荐
- Django零基础(三)
文章目录 前言 一.普通用户输入 1.添加新主题 1.1 表单模型 1.2 新网页URl设定 1.3 修改views.py 1.4 新建网页 1.5 topics链接 2.添加新条目 2.1 条目模型 ...
- Node.js基础入门
Node基础 Node快速体验 1. Node介绍 1.1. Node.js是什么 Node 是一个基于Chrome V8 引擎的JavaScript 运行环境. Node 不是一种独立的语言. No ...
- android逆向分析腾讯微视研究无限循环视频嵌套滑动不中断的实现方式
我这里寻找突破口是寻找适配器文字追踪,因为这布局文件太多了,通过点击方式追踪没有追踪到具体的东西. image.png image.png image.png image.png image.png ...
- python项目NoReverseMatch: Reverse for ‘topic‘ with arguments ‘(‘‘,)‘ not found解决方法
文章目录 遇到的问题 解决方法 参考 遇到的问题 今天在阅读<python编程-从入门到实践>这本书,并且课本上的项目之时,在第18章:将显示所有主题的页面中的每个主题都设置为链接的代码中 ...
- django解决错误Reverse for 'show' with arguments '()' and keyword arguments '{}' not found. 办法
保留个犯罪现场吧: 出现的错误 NoReverseMatch at / Reverse for 'show' with arguments '()' and keyword arguments '{} ...
- PEP 634 – Structural Pattern Matching: Specification
PEP 634 – Structural Pattern Matching: Specification PEP 634 – 结构化模式匹配:规范 PEP: 634 Title: Structural ...
- prototype.js 1.4版开发者手册
prototype.js是什么? 万一你没有使用过大名鼎鼎的prototype.js,那么让我来告诉你,prototype.js是由Sam Stephenson写的一个javascript类库.这个构 ...
- django NoReverseMatch 错误问题
对照这django官方教程(1.8)写第一个APP,在第3部分(Removing hardcoded URLs in templates),将index.html的链接<a href=" ...
- django html跳转页面跳转页面,Django html单击打开另一个html页面
我目前在使用django打开html页面时遇到了问题,尽管我已经尝试在网址.py, 视图.py,以及html页面.我的代码如下: 电池电流.py在"视图"文件夹下from __fu ...
最新文章
- android通过webservice连接SQL数据库(二)客户端
- angular_ui-router ——依赖注入
- tomcat各目录(文件)作用
- lisp scheme 果壳_走出Lisp(Scheme)困境
- PyTorch 1.0 中文文档:torch.utils.cpp_extension
- clion远程调试linux内核,Clion + 树莓派/Ubuntu 远程调试
- 年终总结系列6:借与贷,科普LTV指标
- html JS实现下拉菜单,vue.js怎么实现下拉框
- Spring Boot 使用Dubbo 创建Hello Wrold
- LeetCode 简单等级
- 自动化测试Linux和fio,一种基于fio实现的SSD性能自动化测试方法与流程
- 2008 iis php mysql_2008服务器配置iis7+php+mysql
- oracle数据库imp命令,数据库imp导入命令
- Git 笔记 - git rebase
- 基于深度神经网络实现的kws系统
- 两两组合工具之itertools
- 如何通过SQL Server语句查询三个月内的信息代码的教程方法
- 如何用Word制作流程图(一)
- OS20190301
- 看互联网将如何颠覆这17个传统行业
热门文章
- Fedora配置清华镜像源或者阿里云镜像源
- Python列表:list
- php自学建议_如何高效自学PHP?
- oracle餐饮权,初秋来临,献上餐饮数字化经营的“暖心大餐”
- python netsnmp_在Ubuntu18.04中关于Python使用netsnmp进行snmp编程
- matlab分析机翼,基于Matlab对机翼断面下轮廓线的数值分析
- k8s部署tomcat及web应用_k8s部署tomcat应用服务
- mysql 合并相加_mysql 多条记要判断相加减合并一条
- jQuery移出style
- 11.Java 面试题整理(编程题)