簡體   English   中英

使用帶有 Postgresql 數據庫的 Flask-WTForm 登錄表單

[英]Login form using Flask-WTForm with Postgresql database

提前致謝!! 我做了以下事情來創建登錄或登錄表單:- 1)創建密鑰 2)使用 LoginManager 並通過應用程序 3)為 login.html 創建路由

當我訪問本地主機上的登錄頁面時,我得到了一個 Method Not Allowed 頁面。

這是代碼:-

應用程序

``` 

from flask import Flask, render_template, request, flash, redirect, url_for, session, logging
    from flask_login import LoginManager

    from config import Config

    app = Flask(__name__)
    app.config.from_object(Config)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:password@localhost/learning'
    db = SQLAlchemy(app)
    # LoginManager
    login_manager = LoginManager(app)# Login Form class


@app.route('/login', methods=['GET,''POST'])
def login():

    if request.method == 'POST':
        # get form fields
        username = request.form['username']
        password_candidate = request.form['password']

        # getting user
        login_user = Flask_Users.query.filter_by(username).first()

        if login_user > 0:
            # Get stored hash
            password = login_user.password  # is this right way to get one field from login_user??
            # Compare passwords
            if sha256_crypt.verify(password_candidate, password):
                app.logger.info('PASSWORD MATCHED')

        else:
            app.logger.info('NO user')

    return render_template('login.html')```

login.html
```


 {% extends 'layout.html' %}

    {% block body %}
      <h1>Login</h1>
        {% include 'includes/_messages.html' %}

      <form action="" method="POST">
        <div class="form-group">
          <label>Username</label>
          <input type="text" name="username" class="form-control" value={{request.form.username}}>
        </div>
        <div class="form-group">
          <label>Password</label>
          <input type="password" name="password" class="form-control" value={{request.form.password}}>
        </div>
        <button type="submit" class="btn btn-primary">Submit</button>
      </form>
    {% endblock %}

I followed what was in the documentation page. In the console, I am getting code 405 and error is the pic[enter image description here][1]


  [1]: https://i.stack.imgur.com/fkf0m.png

Any help is appreciated. I did go through relevant posts on the website as well, but could not find anything relatable

你的代碼有錯別字

methods=['GET,''POST']

你需要糾正

methods=['GET','POST']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM