django页面查询显示问题

Q446512799 2019-03-16 11:12:39
我的views.py是这样的:
def findinfo(request):
return render(request,'findinfo.html')

def findresult(request):
items = []
testline = {}
for i in range(10):
testline['name'] = "nxy"
testline['id'] = "123456"
items.append(testline.copy())

return render(request,'findinfo.html',{'items':items})


我的findinfo.html模板是这样的:
<!DOCTYPE html>
<html>
<head>
<title>查询页面</title>
</head>
<body>


<form align="center" action="/findresult/" method="get">
查询条件: <input type="text" id="name" name="name"> <br><br>
<button type="button" id='find'>查询</button>
</br></br>

</form>

<table class="gridtable" align="center" id="pstable" border="1">

<thead>
<tr>
<th>姓名</th>
<th>编号</th>
</tr>
</thead>

<tbody>
{%for item in items%}
<tr>
<td>{{item.name}}</td>
<td>{{item.id}}</td>
</tr>
{% endfor %}
</tbody>

</table>
</body>
</html>

<script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#find").click(function(){
$.get("/findresult/",{'name':name},
function(ret){
$('#pstable').html(ret)
})
});
});
</script>

打开页面显示:

点击查询显示:


table里又嵌入了一层查询按钮,这个怎么解决啊
...全文
463 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Q446512799 2019-03-18
  • 打赏
  • 举报
回复
第二种方法可行,就是太绕了
Q446512799 2019-03-18
  • 打赏
  • 举报
回复
引用 2 楼 陈年椰子 的回复:
方法1 、

我觉得你可以试着把这段注释掉
<script>
$(document).ready(function(){
$("#find").click(function(){
$.get("/findresult/",{'name':name},
function(ret){
$('#pstable').html(ret)
})
});
});
</script>

这段代码把整个页面的结果帖到到 table 区域, 包含了 查询文本框及按钮。

你的form 里已经有 action 了, 不需要这部分的JS 。


方法2、 保留JS代码
另外做一个模板, showinfo.html
这个模板只包含table 信息, 不包含FORM 查询文本框及按钮。

def findresult(request): 里的语句改一下

return render(request,'showinfo.html',{'items':items})

终于有人了,我先试试看,感谢了
陈年椰子 2019-03-18
  • 打赏
  • 举报
回复
方法1 、 我觉得你可以试着把这段注释掉 <script> $(document).ready(function(){ $("#find").click(function(){ $.get("/findresult/",{'name':name}, function(ret){ $('#pstable').html(ret) }) }); }); </script> 这段代码把整个页面的结果帖到到 table 区域, 包含了 查询文本框及按钮。 你的form 里已经有 action 了, 不需要这部分的JS 。 方法2、 保留JS代码 另外做一个模板, showinfo.html 这个模板只包含table 信息, 不包含FORM 查询文本框及按钮。 def findresult(request): 里的语句改一下 return render(request,'showinfo.html',{'items':items})
Q446512799 2019-03-16
  • 打赏
  • 举报
回复
刚开始学,求助

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧