首页 新闻 会员 周边

Django框架对MongoDB实现查询并返回web页面?

0
悬赏园豆:180 [已关闭问题] 关闭于 2021-05-19 14:59

现在我已经写好了MongoDB展示数据、删除数据、添加数据的后端代码和前端代码,需要写一个按条件查询的功能,比如数据字段是公司、姓名、电话、地区,我要按地区查询,然后会把一整条的数据(公司、姓名、电话、地区)都展现出来,下面是我在网上查的:

def find(request):
region = request.POST.get("region", None)
message = None
all_message = invitation.objects(region=region)
if all_message:
message = all_message[0]

return render(request, 'find.html',message)

下面是HTML代码:

<form action="/find/" method="post">
请输入地区(仅支持按地区搜索):<input type="text" name="company" style="width: 500px" placeholder="请输入地区"><br>
<input type="submit" value="确定">
</form>
<table>
<thead>
<th>公司</th>
<th>联系人</th>
<th>电话</th>
<th>地址</th>
<th>经营范围</th>
<th>法人</th>
<th>类型</th>
<th>成立时间</th>
<th>注册资金</th>
<th>员工人数</th>
<th>网址</th>
<th>地区</th>
<th>来源</th>
<th>公司介绍</th>
<th>行业</th>
</thead>
<tbody>
{% for item in invitation %}
<tr>
<td>{{ item.company }}</td>
<td>{{ item.contacts }}</td>
<td>{{ item.Telephone }}</td>
<td>{{ item.address }}</td>
<td>{{ item.product }}</td>
<td>{{ item.person }}</td>
<td>{{ item.type }}</td>
<td>{{ item.time }}</td>
<td>{{ item.capital }}</td>
<td>{{ item.Number }}</td>
<td>{{ item.web }}</td>
<td>{{ item.region }}</td>
<td>{{ item.source }}</td>
<td>{{ item.introduce }}</td>
<td><a>{{ item.industry }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>

Acheng1011的主页 Acheng1011 | 初学一级 | 园豆:26
提问于:2021-05-18 16:33
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册