以下是我的HTML页面:
<form action = "{{url_for('enter_ID')}}" method = "POST">
<select name = "ID">
<option value="ID1">Galactic_ID</option>
<option value="ID2">Phone_ID</option>
<option value="ID3">ident_ID</option>
</select>
ID:<input type = "text" name = "ID" />
<input type='submit' value='Submit'>
下面是我的views.py:
from models1 import Customer,Phone,ID_Card
from flask import Flask, request, session, redirect, url_for, render_template, flash,json,jsonify
import os
app = Flask(__name__)
@app.route('/',methods = ['GET','POST'])
def enter_ID():
if request.method == 'POST':
Galactic_ID = request.form['ID']
if Customer(Galactic_ID).find():
data = Customer(Galactic_ID).Customer_relationships()
return render_template('dropdown.html',data=json.dumps(data))
Phone_ID = request.form['ID']
if Phone(Phone_ID).find():
data = Phone(Phone_ID).Phone_relationships()
return render_template('dropdown.html',data=json.dumps(data))
ident_ID = request.form['ID']
if ID_Card(ident_ID).find():
data = ID_Card(ident_ID).ID_Card_relationships()
return render_template('dropdown.html',data=json.dumps(data))
else:
return render_template('dropdown.html')
我收到错误:
ValueError: View function did not return a response
我的dropdown.html确实拥有渲染d3.js图所需的CSS和其他详细信息。我还没有找到将下拉列表连接到Flask的标准方法。所以,想到在这里发布它。
答案 0 :(得分:0)
如果请求方法是POST
,但没有任何过滤器触发,则没有达到return
语句,因此返回None
,这不是有效的响应。
在最后else
之前删除render_template
。