Этот код из route.py
файла выдает ошибку:
if user and bcrypt.check_password_hash(user.password,
request.form.get('password')):
Это ошибка:
TypeError: ожидаемая строка или буфер
Я использую VM virual box linux, это route.py
файл:
from flask import Flask, render_template,request,flash,redirect, url_for
from blog import app, db, bcrypt, login_manager
from flask_login import login_user, login_required, current_user, logout_user
from .models import User
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method=="POST":
user = User.query.filter_by(username=request.form.get('username')).first()
# This line make an error
if user and bcrypt.check_password_hash(user.password,
request.form.get('password')):
login_user(user)
flash('Logged in successfully','success')
next = request.args.get('next')
return redirect(next or url_for('dashboard'))
flash('Wrong password try again','danger')
return render_template('admin/login.html')
@app.route('/dashboard')
def dashboard():
return "Thank for register"
Это __init__.py
файл:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:123456@localhost:5000/fortest'
app.config['SECRET_KEY']='dedgaoj'
db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
login_manager.login_view = "users.login"
login_manager.login_message_category = "info"
from blog import routes
Я ожидал return redirect(next or url_for('dashboard'))