【发布时间】:2020-07-10 03:08:22
【问题描述】:
我一直在使用用于 DB 的 sqlite3 在 Flask 中开展一个小型项目。该项目是关于如何保护患者的医疗记录。我有两个视图,一个是让管理员插入新患者并查看他们的详细信息,另一个是让患者查看他们的记录。 我的问题是,当管理员插入新患者时,该特定患者的姓名和 ID 将被添加到动态 html 表以及该表中的患者列表中,他可以单击特定患者查看他/她的记录。但我无法映射患者记录的查看部分。 我收到一个运行时错误,上面写着 TypeError: The view function did not return a valid response。该函数要么返回 None 要么在没有返回语句的情况下结束 以下是模板:
包含患者姓名和 ID 的动态表:
{% block content %}
<form method="post" action="{{ url_for('custom') }}">
<table>
<thead>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</thead>
{% for row in rows %}
<tr>
<td name="userid1"><a href="{{ url_for('custom') }}" >{{ row.Userid }}</a></td>
<input type="hidden" id="id" name="userid1" value=" {{ row.Userid }}"/>
<td name="names1"><a href="{{ url_for('custom') }}" > {{row.Name}}</a></td>
<input type="hidden" id='na' name="names1" value="{{row.Name}}" />
<td> {{ row["Age"]}}</td>
</tr>
{% endfor %}
</table>
<br><br>
</form>``
{% endblock %}
病历页面(查看):
</div>
</div>
<div class="details" style="height:550px;" >
<img src="static/images/bg2.png" style="width:250px;height:300px;margin-top:3%;">
<div class="contentin">
<p class="tit1"><b>{{ infos[1] }}</b></p>
<b><p class="tit2">Age: <font style="color:black;">{{ infos[2] }}</font></p>
<p class="tit2">Sex: <font style="color:black;">{{ infos[3] }}</font></p>
<p class="tit2">Height: <font style="color:black;">{{ infos[4] }}</font></p>
<p class="tit2">Weight: <font style="color:black;">{{ infos[5] }}</font></p>
<p class="tit2">Sugar Level: <font style="color:black;">{{ infos[6] }}</font></p>
<p class="tit2">BP Level: <font style="color:black;">{{ infos[7] }}</font></p>
</b>
<button class="btn" style="width:350px;"><font style="color:white;"><b>Download All Reports <i class="fa fa-download"></i></button>
<button class="btn" style="width:300px;">Share <i class="fa fa-share-alt"></i></b></font></button></center>
</div>
</div>
我的 Flask .py 文件:
@app.route('/patientinfo')
def patientinfo():
conn = sqlite3.connect('patients.db')
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute("select Userid,Name,Age from details")
rows = c.fetchall()
return render_template("patientinfo.html", rows=rows)
@app.route('/hospital', methods=['GET', 'POST'])
def custom():
User_ID = request.form.get("userid1")
Name = request.form.get("names1")
conn = sqlite3.connect('patients.db')
cul = conn.cursor()
cul.execute('SELECT Userid, Name, Age, Sex, Height, Weight, Sugar, BP from details')
pt = cul.fetchall()
for pat in pt:
if pat[0] == User_ID:
if pat[1] == Name:
return render_template("hospital.html", infos=pat)
【问题讨论】:
标签: python html forms sqlite flask