Ошибка 401 при запуске flask-приложения
Пытаюсь вывести форму авторизации при запуске приложения, возвращается ошибка 401. Прошу помочь с данной проблемой.
conn = psycopg2.connect(dbname=DB_NAME, user=DB_USER, password=DB_PASS, host=DB_HOST)
login_manager = LoginManager()
login_manager.init_app(app)
@login_manager.user_loader
def load_user(user_id):
return get(user_id)
class User(UserMixin):
def __init__(self, username, password):
self.id = username
self.password = password
@staticmethod
def get(username):
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute("SELECT id, username, password FROM users WHERE username = %s", (username,))
user_data = cur.fetchone()
if user_data:
return User(id=user_data[0], username=user_data[1], password=user_data[2])
else:
return None
@app.route('/register', methods=['GET', 'POST'])
def register():
form = RegistrationForm()
if form.validate_on_submit():
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
hashed_password = generate_password_hash(form.password.data, method='pbkdf2:sha256')
cur.execute("INSERT INTO users (username, password) VALUES (%s, %s)", (form.username.data, hashed_password))
conn.commit()
flash('Registration successful! You can now log in.', 'success')
return redirect(url_for('login'))
return render_template('register.html', title='Register', form=form)
@app.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
if form.validate_on_submit():
user = get(form.username.data)
if user and check_password_hash(user.password, form.password.data):
login_user(user)
flash('Login successful!', 'success')
return redirect(url_for('FO'))
else:
flash('Login unsuccessful. Please check your username and password.', 'danger')
return render_template('login.html', title='Login', form=form)
@app.route('/')
@login_required
def FO():
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
s = "SELECT * FROM public.fo"
cur.execute(s)
fo = cur.fetchall()
return render_template('fo.html', fo = fo)