【问题标题】:How to get the currently clicked radio button如何获取当前点击的单选按钮
【发布时间】:2015-11-26 11:23:49
【问题描述】:

我正在为大学做一个 Python 项目,我必须从中创建一个用户登录/注册系统,该系统将包含管理员和标准用户会话,为了简单起见,用户可以在注册时选择它的用户权限signup.html 文件中的单选按钮形式。

    <form action="/signup" method="post">
    <label for="inputEmail" class="sr-only">Email address</label>
    <input type="email" name="inputEmail" id="inputEmail" class="form-control" maxlength="45" placeholder="Email address" required autofocus>
    <label for="inputPassword" class="sr-only">Password</label>
    <input type="password" name="inputPassword" id="inputPassword" class="form-control" maxlength="45" placeholder="Password" required>

<input type="radio" name="userRole" value="standard">Standard
<input type="radio" name="userRole" value="admin">Admin
    <br><br><br>
    <button class="btn btn-lg btn-primary btn-block" type="submit">Signup</button>
  </form>

在我的 python 代码中,我能够获取用户名和密码,但我不确定如何获取当前单击按钮的值。

if request.method == 'POST':
        _email = request.form['inputEmail']
        _password = request.form['inputPassword']
        _access = request.form[ .... ]

感谢任何帮助,谢谢

【问题讨论】:

  • 你试过request.POST['userRole']吗?
  • @JasonEstibeiro 那没用,但我想出了解决方案。

标签: python


【解决方案1】:

我的问题的解决方法很简单,和之前表单中的请求完全一样:

_access = request.form['userRole']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多