Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未在Python中从一个HTML表单到另一个表单获取所选单选按钮值_Python_Html_Flask_Jinja2 - Fatal编程技术网

未在Python中从一个HTML表单到另一个表单获取所选单选按钮值

未在Python中从一个HTML表单到另一个表单获取所选单选按钮值,python,html,flask,jinja2,Python,Html,Flask,Jinja2,我有一个带有单选按钮的主页。我选择一个项目(数据库类型),并希望在python代码中获得选中的值,然后在一些验证之后,希望显示另一个表单以连接到选定的数据库类型。但是在尝试了这么多东西之后,我无法获得所选的单选按钮值,然后无法处理下面的conndb.html。我对pythonweb开发相当陌生。没有得到任何工作,以满足这一要求。主页pyhton代码为 @bp.route('/') def index(): db = get_db() if request.method == 'GET':

我有一个带有单选按钮的主页。我选择一个项目(数据库类型),并希望在python代码中获得选中的值,然后在一些验证之后,希望显示另一个表单以连接到选定的数据库类型。但是在尝试了这么多东西之后,我无法获得所选的单选按钮值,然后无法处理下面的conndb.html。我对pythonweb开发相当陌生。没有得到任何工作,以满足这一要求。主页pyhton代码为

@bp.route('/')
def index():
db = get_db()
if request.method == 'GET':
    posts = db.execute(
            'SELECT id, DB_Tp'
            ' FROM DB_Type'
            ' ORDER BY DB_Tp ASC'
            ).fetchall()

    error = None
    if len(posts) == 0:
        error = 'No Database Type To Choose For Meta Data. Create New Entry'
        flash(error)

    return render_template('meta/index.html', posts = posts)
else:           **#=> from here the code is never executed. It always falls thru to next function**

    checked = request.form['dbtype']
    print("This is ", checked, flush = True)
    if checked == "MySql":
        return render_template('meta/conndb.html')
    else:
        error = "Nothing checked "
        flash(error)
        return redirect(url_for("meta.index")) 
html是-

{% extends 'base.html' %}

{% block header %}
  <h1>{% block title %}Select Database Type{% endblock %}</h1>

{% endblock %}

{% block content %}
   <form class="post" action="/conndb">
{% for post in posts %}
    <label class="body">
    <input type="radio" name="dbtype" required>{{post['DB_TP']}}</label><br>
{% if not loop.last %}
{% endif %}
{% endfor %}    
    <button type="submit">Next</button>
</form>
<hr>
{% endblock %}
{%extends'base.html%}
{%块头%}
{%block title%}选择数据库类型{%endblock%}
{%endblock%}
{%block content%}
{posts%%中的post为%s}
{{post['DB_TP']}}
{%if not loop.last%} {%endif%} {%endfor%} 下一个
{%endblock%}
根据选择的单选按钮,我想对不同类型的DB执行不同的操作。从所选单选按钮获取值后,我渲染此模板以连接到数据库。。。 conndb.html

{% extends 'base.html' %}

{% block header %}
   <h1>{% block title %}Provide Details To Connect To Database{% endblock %}</h1>
{% endblock %}

{% block content %}
 <form method="post">
 <label for="host">Host Name</label>
 <input name="host" id="host" required>
 <label for="user">User ID</label>
 <input name="user" id="user" required>
 <label for="passwd">Password</label>
 <input type="password" name="passwd" id="passwd" required>
 <label for="db">Schema</label>
 <input name="db" id="db" required>
 <input type="submit" value="Get MetaData">
 </form>
{% endblock %} 
{%extends'base.html%}
{%块头%}
{%block title%}提供连接到数据库的详细信息{%endblock%}
{%endblock%}
{%block content%}
主机名
用户ID
暗语
模式
{%endblock%}
非常感谢您的帮助。

无线电html中缺少“值”属性

e、 g:

{{post['DB_-TP']}}

感谢您的回复。它仍然不起作用。我仍然得到“TypeError:view函数未返回有效响应。该函数要么未返回任何响应,要么在没有返回语句的情况下结束。”我的浏览器显示类似于“”的内容,并转到conndb.html-这非常好。我的问题是,在呈现conndb.html模板之前,我想在python Flask代码中捕获dbtype=MySql。感谢您的输入。我想这是一个不同的问题,无论如何:request.args.get('dbtype')谢谢。我得到了你的指导。谢谢。
<input type="radio" name="dbtype" value="{{post['DB_TP'].id}}" required>{{post['DB_TP']}}</label><br>