flask 相关问题

Flask是一个用于使用Python开发Web应用程序的轻量级框架。

我已经将烧瓶应用程序部署到Azure Web应用程序服务。本地我有一个包含以下内容的文件:

I在Azure Web应用程序的“环境变量”部分中创建了一个环境变量。

回答 0 投票 0







返回错误代码和消息给API呼叫者

I有一个Web应用程序,该应用程序使用SQLalchemy将一些数据放入数据库中:如果元素不存在,则添加了其他数据。在这两种情况下,它都显示出...

回答 1 投票 0


带烧瓶 - wtf,验证器

代码如下: wtf.py: 从烧瓶导入烧瓶,render_template,重定向,url_for,请求,flash 从表格导入myform 从flask_wtf导入csrfprotect app =烧瓶(__名称__) app.con ...

回答 1 投票 0


我如何向我的烧瓶应用程序提供共享状态,而不依赖其他软件?

我想为烧瓶应用提供共享状态,该应用程序与多个工人一起运行。 e。多个过程。 引用有关此主题的类似问题的答案: 您不能使用全局变量...

回答 3 投票 0


如何处理用户在python中使用烧瓶登录? 我正在开发带有Python烧瓶的基本Web应用程序,我正在尝试根据是否有登录用户来修改我使用的一些模板。我正在使用MongoDB来存储用户数据。 下面...

auth_blueprint = Blueprint('auth', __name__, template_folder='templates') # Setup Flask-Login and Bcrypt bcrypt = Bcrypt() login_manager = LoginManager() login_manager.login_view = "auth.login" # MongoDB configuration mongo_uri = config.mongo_uri client = MongoClient(mongo_uri) db = client[config.DB_NAME] users_collection = db["users"] # User class for Flask-Login class User(UserMixin): def __init__(self, id, username, password): self.id = id self.username = username self.password = password @staticmethod def get(user_id): user_data = users_collection.find_one({"_id": user_id}) if user_data: return User(str(user_data["_id"]), user_data["username"], user_data["password"]) return None def get_id(self): return self.id @login_manager.user_loader def load_user(user_id): print(f'load_user method is called and the user_id is {user_id}') try: return User.get(user_id) except: return None @auth_blueprint.route("/register", methods=["GET", "POST"]) def register(): if request.method == "POST": username = request.form["username"] password = request.form["password"] confirmed_password = request.form["repeat-password"] if not username: flash("Please enter a username.", "danger") return redirect(url_for("auth.register")) if users_collection.find_one({"username": username}): flash("Username already exists!", "danger") return redirect(url_for("auth.register")) if not password: flash("Please enter a password.", "danger") return redirect(url_for("auth.register")) if not confirmed_password: flash("Please confirm the password.", "danger") return redirect(url_for("auth.register")) if password != confirmed_password: flash("Passwords must match!", "danger") return redirect(url_for("auth.register")) hashed_password = bcrypt.generate_password_hash(password).decode("utf-8") users_collection.insert_one({"username": username, "password": hashed_password}) flash("Registration successful!", "success") return redirect(url_for("auth.login")) return render_template("register.html") @auth_blueprint.route("/login", methods=["GET", "POST"]) def login(): if request.method == "POST": username = request.form["username"] password = request.form["password"] # Check if the user exists and credentials are valid user_data = users_collection.find_one({"username": username}) print(user_data) if user_data and bcrypt.check_password_hash(user_data["password"], password): session.clear() user = User(str(user_data['_id']), user_data['username'], user_data['password']) print(f'User id is {user.id}') result = login_user(user, remember=True, duration=timedelta(days=7), force=True) session.modified = True print(f'Is user authenticated in login function: {current_user._get_current_object().is_authenticated}') # print(f'Current user type is {type(current_user.is_authenticated)}') if result: print("Loggin successful!") #print(f"Session after login: {session}") # Inspect session object flash("Login successful!", "success") return redirect(url_for("index")) else: print("Something went wrong :(") return redirect(url_for("auth.login")) # session['username'] = user.username # if not helpers.url_has_allowed_host_and_scheme(next, request.host): # return abort(400) else: flash("Invalid credentials!", "danger") return render_template("login.html") @auth_blueprint.route("/check_login") def check_login(): print(f'Is user authenticated in check_login function: {current_user._get_current_object().is_authenticated}') print(type(current_user._get_current_object())) if current_user._get_current_object().is_authenticated: return f"User {current_user.name} is logged in." else: return "No user is logged in."

回答 0 投票 0





emit用blask_socketio

GPUMonitorService

回答 1 投票 0

未来的flask可持续性

I使用烧瓶作为服务器侧框架构建了SaaS Web应用程序。 从一段时间开始,我担心未来的烧瓶和烧瓶扩展。 引用,

回答 1 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.