Поэтому я пытаюсь предложить пользователю ввести что-то в веб-приложение, которое выполняет поиск в моей базе данных и возвращает строку в таблицу на веб-странице. Тем не менее, я не уверен, где я портю. Я думаю, что это в моем возвращении на flask_app.py, но не уверен, что это сделать. Любой совет? Я убегаю от питона где угодно. Выдает ошибку при вводе чего-либо в строку поиска. Ошибка говорит мне, что перенаправление возврата (url_for ('Patient_info_page'), запрос = поиск) является неправильным. Когда я впервые открываю страницу, таблица базы данных подтягивается. но я пытаюсь позволить пользователю искать в БД по mrn.
Точная ошибка ниже моего кода.
flask_app.py
class patient_ID(db.Model):
__tablename__ = "patient_ID"
incounter_types = [('inpatient', 'inpatient'),
('outpatient', 'outpatient')
]
lname = db.Column(db.String(128))
fname = db.Column(db.String(128))
ssn = db.Column(db.String(9),nullable=False)
mrn = db.Column(db.String(8),primary_key=True,nullable=False)
age = db.Column(db.String(3))
sex = db.Column(db.String(6))
incounter_type = db.Column(db.String(128))
provider_lname = db.Column(db.String(128))
provider_fname = db.Column(db.String(128))
admin_date = db.Column(db.String(128))
admin_time = db.Column(db.String(128))
location_hospital = db.Column(db.String(128))
location_floor = db.Column(db.String(3))
location_room = db.Column(db.String(10))
location_bed = db.Column(db.String(1))
@app.route("/Patient_Info/", methods=["GET", "POST"])
@login_required
def patient_info_page():
if request.method == "GET":
return render_template("ID.html", query=patient_ID.query.all())
if not current_user.is_authenticated:
return redirect(url_for('index'))
smrn = request.form["mrns"]
search = db.session.query(patient_ID).filter_by(mrn = smrn).all()
return redirect(url_for('patient_info_page'), query=search)
ID.html
{% if current_user.is_authenticated %}
<div id="tfheader">
<form id="tfnewsearch" method="POST" action=".">
<input type="text" class="form-control" name="mrns" size="21" maxlength="8" placeholder="Enter Patient MRN"><input type="submit" value="search" class="tfbutton">
</form>
<div class="tfclear"></div>
</div>
{% endif %}
<table style="margin-left: 20px;">
<!-- Table headers -->
<th>
<tr style="color: black; ">
<th>Last Name</th>
<th>First Name</th>
<th>SSN</th>
<th>MRN</th>
<th>Age</th>
<th>Sex</th>
<th>Incounter Type</th>
<th>Provider Last Name</th>
<th>Provider First Name</th>
<th>Admin Date</th>
<th>Admin Time</th>
<th>Hospital</th>
<th>Floor</th>
<th>Room</th>
<th>Bed</th>
</tr>
</th>
{%for patient_id in query%}
<tr>
<td>
{{patient_id.lname}}
</td>
<td>
{{patient_id.fname}}
</td>
<td>
{{patient_id.ssn}}
</td>
<td>
{{patient_id.mrn}}
</td>
<td>
{{patient_id.age}}
</td>
<td>
{{patient_id.sex}}
</td>
<td>
{{patient_id.incounter_type}}
</td>
<td>
{{patient_id.provider_lname}}
</td>
<td>
{{patient_id.provider_fname}}
</td>
<td>
{{patient_id.admin_date}}
</td>
<td>
{{patient_id.admin_time}}
</td>
<td>
{{patient_id.location_hospital}}
</td>
<td>
{{patient_id.location_floor}}
</td>
<td>
{{patient_id.location_room}}
</td>
<td>
{{patient_id.location_bed}}
</td>
</tr>
{%endfor%}
</table>
Ошибка
2019-11-09 01:05:15,153: Error running WSGI application
2019-11-09 01:05:15,157: TypeError: redirect() got an unexpected keyword argument 'query'
2019-11-09 01:05:15,157: File "/home/tomjjoy123/.virtualenvs/flask-tutorial/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
2019-11-09 01:05:15,158: return self.wsgi_app(environ, start_response)
2019-11-09 01:05:15,158:
2019-11-09 01:05:15,158: File "/home/tomjjoy123/.virtualenvs/flask-tutorial/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
2019-11-09 01:05:15,158: response = self.handle_exception(e)
2019-11-09 01:05:15,158:
2019-11-09 01:05:15,158: File "/home/tomjjoy123/.virtualenvs/flask-tutorial/lib/python3.7/site-packages/flask/app.py", line 1866, in handle_exception
2019-11-09 01:05:15,158: reraise(exc_type, exc_value, tb)
2019-11-09 01:05:15,158:
2019-11-09 01:05:15,158: File "/home/tomjjoy123/.virtualenvs/flask-tutorial/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
2019-11-09 01:05:15,159: raise value
2019-11-09 01:05:15,159:
2019-11-09 01:05:15,159: File "/home/tomjjoy123/.virtualenvs/flask-tutorial/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
2019-11-09 01:05:15,159: response = self.full_dispatch_request()
2019-11-09 01:05:15,159:
2019-11-09 01:05:15,159: File "/home/tomjjoy123/.virtualenvs/flask-tutorial/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
2019-11-09 01:05:15,159: rv = self.handle_user_exception(e)
2019-11-09 01:05:15,159:
2019-11-09 01:05:15,159: File "/home/tomjjoy123/.virtualenvs/flask-tutorial/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
2019-11-09 01:05:15,160: reraise(exc_type, exc_value, tb)
2019-11-09 01:05:15,160:
2019-11-09 01:05:15,160: File "/home/tomjjoy123/.virtualenvs/flask-tutorial/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
2019-11-09 01:05:15,160: raise value
2019-11-09 01:05:15,160:
2019-11-09 01:05:15,160: File "/home/tomjjoy123/.virtualenvs/flask-tutorial/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
2019-11-09 01:05:15,160: rv = self.dispatch_request()
2019-11-09 01:05:15,160:
2019-11-09 01:05:15,161: File "/home/tomjjoy123/.virtualenvs/flask-tutorial/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
2019-11-09 01:05:15,161: return self.view_functions[rule.endpoint](**req.view_args)
2019-11-09 01:05:15,161:
2019-11-09 01:05:15,161: File "/home/tomjjoy123/.virtualenvs/flask-tutorial/lib/python3.7/site-packages/flask_login/utils.py", line 261, in decorated_view
2019-11-09 01:05:15,161: return func(*args, **kwargs)
2019-11-09 01:05:15,161:
2019-11-09 01:05:15,161: File "/home/tomjjoy123/mysite/flask_app.py", line 186, in patient_info_page
2019-11-09 01:05:15,161: return redirect(url_for('patient_info_page'), query=search)