- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我启动我的应用程序时出现此错误。显然它与 SQLAlchemy 有一些关系。我一直在 Corey Schaffer Flask 教程的帮助下处理这个例子。
> File "C:\Users\Matea\venv\lib\site-packages\flask\app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\Matea\venv\lib\site-packages\flask\app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\Matea\venv\lib\site-packages\flask\app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Matea\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Users\Matea\venv\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Matea\venv\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\Matea\venv\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Matea\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Users\Matea\venv\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Matea\venv\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\Matea\myblog\myblog\main\routes.py", line 11, in home
posts = Post.query.order_by(Post.date_posted.desc()).paginate(page=page, per_page=5)
File "C:\Users\Matea\venv\lib\site-packages\flask_sqlalchemy\__init__.py", line 514, in __get__
return type.query_class(mapper, session=self.sa.session())
File "C:\Users\Matea\venv\lib\site-packages\sqlalchemy\orm\scoping.py", line 74, in __call__
return self.registry()
File "C:\Users\Matea\venv\lib\site-packages\sqlalchemy\util\_collections.py", line 1001, in __call__
return self.registry.setdefault(key, self.createfunc())
File "C:\Users\Matea\venv\lib\site-packages\sqlalchemy\orm\session.py", line 2950, in __call__
return self.class_(**local_kw)
File "C:\Users\Matea\venv\lib\site-packages\flask_sqlalchemy\__init__.py", line 143, in __init__
bind = options.pop('bind', None) or db.engine
File "C:\Users\Matea\venv\lib\site-packages\flask_sqlalchemy\__init__.py", line 877, in engine
return self.get_engine()
File "C:\Users\Matea\venv\lib\site-packages\flask_sqlalchemy\__init__.py", line 896, in get_engine
return connector.get_engine()
File "C:\Users\Matea\venv\lib\site-packages\flask_sqlalchemy\__init__.py", line 556, in get_engine
self._sa.apply_driver_hacks(self._app, info, options)
File "C:\Users\Matea\venv\lib\site-packages\flask_sqlalchemy\__init__.py", line 830, in apply_driver_hacks
if info.drivername.startswith('mysql'):
AttributeError: 'NoneType' object has no attribute 'drivername'
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_mail import Mail
from myblog.config import Config
db = SQLAlchemy()
bcrypt = Bcrypt()
login_manager = LoginManager()
login_manager.login_view = 'users.login'
login_manager.login_message_category = 'info'
mail = Mail()
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)
bcrypt.init_app(app)
login_manager.init_app(app)
mail.init_app(app)
from myblog.users.routes import users
from myblog.posts.routes import posts
from myblog.main.routes import main
from myblog.errors.handlers import errors
app.register_blueprint(users)
app.register_blueprint(posts)
app.register_blueprint(main)
app.register_blueprint(errors)
return app
import os
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY')
SQLALCHEMY_DATABASE_URI = os.environ.get('SQLALCHEMY_DATABASE_URL')
MAIL_SERVER = 'smtp.googlemail.com'
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_USERNAME = os.environ.get('EMAIL_USER')
MAIL_PASSWORD = os.environ.get('EMAIL_PASS')
最佳答案
如果您在 中正确设置了环境变量.bash_proflie
export EMAIL_USER='youremail@gmail.com'
export EMAIL_PASS='Yourpassword'
export SQLALCHEMY_DATABASE_URI='sqlite:///site.db'
export SECRET_KEY='secretkeyxxxxxxxxxxxxxxxx'
from your yourflaskapp import db
db.create_all()
use from yourapp import create_app
app = create_app()
app.app_context().push()
Always refresh your text editor and the terminal after making changes. Also try to make sure you are running your app in the right directory.
关于python-3.x - 属性错误 : 'NoneType' object has no attribute 'drivername' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51727943/
我将 Flask 和 SQLAlchemy 集成到我的应用程序中,但可以理解为什么在登录页面获取大堆栈跟踪。从 Debian 切换到 Mac 操作系统后,我现在会遇到此错误。 virtuaelnv 中
我在 Heroku 上运行应用程序时遇到问题。本地版本似乎工作正常,但我无法在 heroku 平台上调用 create_db()。 这是错误轨迹。 (venv)S-MBP:LaunchPage3 S$
我正在学习 CS50 的 Web Programming with Python and Javascript,在 Lecture4 中,我在尝试创建 postgresql 数据库表时遇到以下错误:
当我启动我的应用程序时出现此错误。显然它与 SQLAlchemy 有一些关系。我一直在 Corey Schaffer Flask 教程的帮助下处理这个例子。 > File "C:\Users\Mate
我正在尝试使用 Flask-SqlAlchemy 连接到 MySQL 数据库,这是我的参数: SQLALCHEMY_DATABASE_URI = 'mysql://root:pass@127.0.0.
我是一名优秀的程序员,十分优秀!