Моя проблема в том, что я впервые пытаюсь настроить систему входа в систему, я последовал этому документации, но при попытке использовать следующий параметр устанавливается на «Нет». Таким образом, я выполнил проверку для выполнения прерывания 400. Я попытался удалить следующую часть и просто продолжить без нее, но тогда мое приложение не сохраняет информацию для входа в систему, и даже несмотря на то, что моя функция входа проверяет все данные и перенаправляет меня в представлении, которое я хочу, после успешного входа в систему отображается сообщение о том, что у меня нет разрешений.
Это мой код:
Код: Выделить всё
@app.route("/login", methods=["POST", "GET"])
def login():
form = SignUpForm()
if request.method == "POST":
user = Blog_User()
form.populate_obj(user)
email_db = db.session.execute(db.select(Blog_User).filter_by(email = user.email)).scalar()
if email_db:
pass_db = db.session.execute(db.select(Blog_User).filter_by(password = user.password)).scalar()
if pass_db:
login_user(user)
flash("Login Suscessfully!")
next = request.args.get('next')
if not url_is_safe(next, request.host):
p = url_is_safe(next, request.host)
return f"The next is: {next}, and the expresion evaluates to: {p}"
return redirect(next or url_for("home"))
else:
flash("Your password was incorrect, try again.")
return redirect("/login")
else:
flash("You dont have an account.")
return redirect("/login")
return render_template("user/login.html", form=form)
@login_manager.user_loader
def load_user(user_id):
return Blog_User.query.get(user_id)
Код: Выделить всё
__pycache__
.venv
app
├── __pycache__
├── forms
│ ├── __pycache__
│ └── sign_up.py
├── helpers
│ ├── __pycache__
│ ├── __init__.py
│ ├── hash_password.py
│ ├── test_data.py
│ ├── test_post.py
│ ├── test_user.py
│ └── url_has_allowed_h.py
├── models
│ ├── __pycache__
│ ├── __init__.py
│ ├── posts.py
│ └── user.py
static
├── img
│ ├── arrow_icon.png
│ └── github-social.png
├── index.css
├── login.css
└── sign_up.css
templates
├── user
│ ├── login.html
│ └── sign_up.html
└── index.html
__init__.py
routes.py
tes.py
instance
├── config.py
└── database_tut.db
.gitignore
config.py
README.md
requirements.txt
run.py
Подробнее здесь: https://stackoverflow.com/questions/792 ... -flask-app
Мобильная версия