May-31-2019, 09:36 PM
I've looked around the web and got all the code from a tutorial I have been going through, but one of my lines isn't working. It is a problem with the query. If I, on debug mode on the website, try Post.query I get "RuntimeError: No application found. Either work inside a view function or push an application context." I can't figure out the problem thanks in advance for the help.
Error comes from second line
Error comes from second line
page = request.args.get('page', 1, type=int) posts = Post.query.order_by(Post.date_posted.desc()).paginate(page=page, per_page=5)run.py (file I run in the command line to start website)
from FlaskBlog import create_app app = create_app() app.app_context().push() if __name__ == '__main__': app.run(debug=True)Here is the create_app funcion in the __init__ file for FlaskBlog
def create_app(config_class=Config): app = Flask(__name__) app.config.from_object(Config) db.init_app(app) bc.init_app(app) login_manager.init_app(app) mail.init_app(app) from FlaskBlog.users.routes import usersApp from FlaskBlog.posts.routes import postsApp from FlaskBlog.main.routes import mainApp app.register_blueprint(usersApp) app.register_blueprint(postsApp) app.register_blueprint(mainApp) return appIf you need it - a tree of the files
FlaskBlog | |--main | |--__init__.py | |--routes.py | |--posts | |--__init__.py | |--forms.py | |--routes.py | |--static | |--a css file and directory full of pictures | |--Templates | |--A ton of html templates | |--users | |--__init__.py | |--forms.py | |--utils.py | |--routes.py | |--__init__.py |--config.py |--models.py |--site.db run.pyI put the tree in a code block so it would maintain the spaces