我一直在尝试为我的烧瓶应用程序创建一个软件包。 我在执行此操作时遇到错误,但以下信息却已给出,尽管我询问是否可以提供,但我已经省略了最大可能的不必要的东西(根据我的看法)。
.
├───flask(venv)
├───.vscode
├───login(package folder)
├───run.py
└───site.db
login
├───static
│ ├───fonts
│ ├───images
│ │ └───icons
│ ├───js
│ └───vendor
├───templates
├───__init__.py
├───forms.py
├───models.py
└───routes.py
# Essential Imports -->
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
#------------------- Application Cofiguuration----------------------------------------
app = Flask(__name__)
app.config['SECRET_KEY'] = 'xxxxxxxxxxxxxf18adb1dxxxxxxx'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)
from login import routes
from login import app
if __name__ == '__main__':
app.run(debug=True)
from login import app
from flask import render_template, url_for, flash, redirect
from login.models import Access, Case
from login.forms import LoginForm
# ------------------ Route management ---------------------------'''
# Home route: the login form
@app.route('/', methods=['GET','POST'])
@app.route('/home', methods=['GET','POST'])
def home():
login_form = LoginForm()
if login_form.validate_on_submit():
flash(f'Lets start analysing.', 'success')
return redirect(url_for('logedin'))
return render_template('index.html', form = login_form)
# Success Route: to redirect the user after successfull login
@app.route('/loggedin')
def logedin():
return render_template('logedin.html')
我遇到的错误处于不同的水平。
我尝试使用 python run.py
直接运行flask应用程序
ImportError: cannot import name 'app' from 'login' (unknown location)
我绑了烧瓶跑
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
然后,我理解并尝试使用 set FLASK_APP = login
为我的静脉设置变量然后烧瓶运行,并出现一个新错误。
Error: Failed to find Flask application or factory in module "login". Use "FLASK_APP=login:name to specify one.
如果您需要我可以提供的其他文件源代码。