【问题标题】:GETTING POST REQUEST ERROR 405 in FLASK WEBFRAMEWORK在 FLASK WEB 框架中获取 POST 请求错误 405
【发布时间】:2021-10-17 17:15:24
【问题描述】:

我已经查看了与此相关的问题的答案,但即便如此,我的问题仍然存在。 基本上我正在烧瓶中制作登录页面。记录存在于我的数据库中而且我在 html、应用程序中使用了方法 = POST 但即使这样我也收到此错误 输出: output

HTML:

<form method="POST">
<div class="row">
  <h2 style="text-align:center; font-family:Courier New; color:#468E85" > Welcome this will be amazing experience:) </h2>
  <div class="vl">
    <span class="vl-innertext">or</span>
  </div>

  <div class="col">
    <a href="https://web.facebook.com/" class="fb btn">
      <i class="fa fa-facebook fa-fw"></i> Login with Facebook
     </a>
    <a href="https://twittermobile..com/login" class="twitter btn">
      <i class="fa fa-twitter fa-fw"></i> Login with Twitter
    </a>
    <a href="https://myaccount.google.com/" class="google btn"><i class="fa fa-google fa-fw">
      </i> Login with Google+
    </a>
  </div>

  <div class="col">
    <div class="hide-md-lg">
      
    </div>
  <label for="username">Username</label>
    <input type="" id="username" name="username" placeholder="Username" value="{{
      request.form.username }}" required>
   <label for="psw">Password</label>

<button type="submit" class="btn form-control btn-default">Login</button>
    <button type="button" class="btn btn-primary">Sign Up</button>
    <div class="msg">{{ msg }}</div>

  <button class="submit" style="color: #008080">Forgot password?</button>

  </div>

  
</div>

APP.py

@app.route('/')
@app.route('/loginform' , methods= ['GET','POST'])
def loginform():
    # Check if "username" and "password" POST requests exist (user submitted form)
    print("herehere")
    if request.method == 'POST' and 'username' in request.form and 'password' in request.form:
    # Create variables for easy access
        print("Hellooo")
        username = request.form['username']
        password = request.form['password']
   #Check if account exists using MySQL
       cursor = mysql.connection.cursor()
       cursor.execute('SELECT * FROM accounts WHERE username = %s AND password = %s', (username,     password,))
    # Fetch one record and return result
      account = cursor.fetchone()
   
        if account is not None:
        # Create session data, we can access this data in other routes
            session['loggedin'] = True
            session['id'] = account['id']
            session['username'] = account['username']
        # Redirect to home page
            print("I am called")
            return redirect('Quickshop.html')
else:
    print("now i am here")
    # Account doesnt exist or username/password incorrect
    msg = 'Incorrect username/password!'
    return render_template('loginform.html',msg = msg)

【问题讨论】:

  • 您是否在表单中明确尝试过action="/loginform"

标签: python html css forms flask


【解决方案1】:

您的 from 标签中的显式操作属性,并且您没有赋值。

试试这个:-

<form method="POST" action="/loginform">                                                                                                                                         
<input type="text" placeholder="Username" name="username" />                             
<input type="password" placeholder="Password" name="password" />                      
<input type="submit" value="Login" />                                                
</form>

您可以在 request.form 中找到密码和用户名。

【讨论】:

    猜你喜欢
    • 2017-12-16
    • 2015-11-07
    • 2017-09-09
    • 2014-12-04
    • 2013-04-21
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多