現在我已經寫好了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="https://bbs.csdn.net/topics/確定">
</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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/284436.html