flask-script

Blueprint initialization, can I run a function before first request to blueprint

给你一囗甜甜゛ 提交于 2019-12-05 02:31:55
Is it possible to run a function before the first request to a specific blueprint ? @my_blueprint.before_first_request def init_my_blueprint(): print 'yes' Currently this will yield the following error: AttributeError: 'Blueprint' object has no attribute 'before_first_request' The Blueprint equivalent is called @Blueprint.before_app_first_request : @my_blueprint.before_app_first_request def init_my_blueprint(): print('yes') The name reflects that it is called before any request, not just a request specific to this blueprint. There is no hook for running code for just the first request to be

Use Flask's Click CLI with the app factory pattern

被刻印的时光 ゝ 提交于 2019-12-04 09:28:35
问题 I define my Flask application using the app factory pattern. When using Flask-Script, I can pass the factory function to the Manager . I'd like to use Flask's built-in Click CLI instead. How do I use the factory with Click? My current code uses Flask-Script. How do I do this with Click? from flask import Flask from flask_script import Manager, Shell def create_app(): app = Flask(__name__) ... return app manager = Manager(create_app) def make_shell_context(): return dict(app=app, db=db, User

deploying flask app with uwsgi and flask-script Manager

隐身守侯 提交于 2019-12-04 08:19:58
Traditionally, I have configured the UWSGI configuration file to call an application like below: mydirectory/uwsgi_application.ini ... #python module to import app = run_web module = %(app) callable = app ... , mydirectory/run_web.py from ersapp import app if __name__ == "__main__": app.run() , mydirectory/ersapp/__init__.py ... app = Flask('ersapp') ... But now, I am following Miguel Grinberg's Flask book and here he uses an application factory like below mydirectory/ersapp/__init__.py ... def create_app(config_name): webapp = Flask(__name__) ... return webapp with a "manager" (see flask

importerror: no module named flask.ext.script

怎甘沉沦 提交于 2019-12-04 05:44:29
In fact I cannot use any pakage now! importerror: no module named flask.ext.script importerror: no module named Pymongo It seems that you virtual environment doesn't work. You've installed the flask-script package, but when you run the script, it still looks for it in C:\Python3.4 . You may give us more info so that we can figure it out where is wrong. (How do you install it, how do you active the virtualenv, does reinstall virtualenv work, close the cmd shell and try again works?) Also note that from flask.ext.extension import xxx is the old way to use the flask extension. Instead you should

Restart flask app in docker on changes

一世执手 提交于 2019-12-03 22:41:57
I am using flask-script to run my app: if __name__ == "__main__": manager.run() In docker I have the following: CMD [ "python", "manage.py", "runserver", "-h", "0.0.0.0", "-p", "5000"] Now when I build and run my container the app runs fine. However, if I make changes to my code and save the app does not restart despite my env having a DEBUG=True variable set. Am I missing something here? Dockerfile: FROM python:3.4-slim RUN apt-get update -y && \ apt-get install -y \ python-pip \ python-dev \ pkg-config \ libpq-dev \ libfreetype6-dev COPY ./requirements.txt /app/requirements.txt WORKDIR /app

Run code after flask application has started

放肆的年华 提交于 2019-11-30 07:02:58
问题 My goal is to get arbitrary code to run after my Flask application is started. Here is what I've got: def run(): from webapp import app app.run(debug=True, use_reloader=False) Ideally I would be able to just do this: def run(): from webapp import app app.run(debug=True, use_reloader=False) some_code() But the code doesn't continue past app.run() , so some_code() never runs. The solution I'm working on at the moment is to run some_code() in a separate thread from app.run(), create a before