inveniosoftware-attic / flask-appfactory Goto Github PK
View Code? Open in Web Editor NEWProject has been deprecated.
Home Page: http://flask-appfactory.readthedocs.org
License: Other
Project has been deprecated.
Home Page: http://flask-appfactory.readthedocs.org
License: Other
The name "extensions" as used in Flask-AppFactory causes some confusion with Flask Extensions hence the name might not be the most appropriate.
Concepts:
Flask extensions: As defined on http://flask.pocoo.org/docs/0.10/extensiondev/ and examples on http://flask.pocoo.org/extensions/.
Here a very simplified example of a factory function where Flask extensions are being initialised:
def create_app():
app = Flask("myapp")
db = FlaskSQLAlchemy(app)
cache = FlaskCache(app)
return app
def create_app():
class config:
EXTENSIONS = ["sqlachemy","cache"]
return appfactory("myapp", config)
#sqlalchemy.py
def setup_app(app):
db = FlaskSQLAlchemy(app)
#cache.py
def setup_app(app):
cache = FlaskCache(app)
To complicate things, it is actually possible to not have a setup_app
method, if you Flask-Extension just takes an app
argument`` (see example):
def create_app():
class config:
EXTENSIONS = ["flask_sqlalchemy:FlaskSQLAlchemy", "flask_cache:FlaskCache"]
return appfactory("myapp", config)
I.e. the main purpose of Flask-AppFactory extensions is to initialise a Flask Application.
Proposals:
I first bumped into this following the example instructions, then replicated it by checking out the examples from github page. I started with a fresh 14.04 Ubuntu VM. Then installed AppFactory:
sudo pip install Flask-AppFactory
cd ~/flask-appfactory/examples
sudo python setup.py install
And then trying out the application:
$ myapp testsimple
Test
$ myapp testapp
Traceback (most recent call last):
File "/usr/local/bin/myapp", line 9, in <module>
load_entry_point('MyApp==1.0', 'console_scripts', 'myapp')()
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 664, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask_cli/cli.py", line 343, in main
return AppGroup.main(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 644, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 991, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 837, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 464, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask_cli/cli.py", line 209, in decorator
with __ctx.ensure_object(ScriptInfo).load_app().app_context():
File "/usr/local/lib/python2.7/dist-packages/flask_cli/cli.py", line 185, in load_app
rv = self.create_app(self)
File "/usr/local/lib/python2.7/dist-packages/flask_appfactory/cli.py", line 85, in create_cli_app
load_application(app)
File "/usr/local/lib/python2.7/dist-packages/flask_appfactory/app.py", line 126, in load_application
extensions=ExtensionRegistry(app),
File "/usr/local/lib/python2.7/dist-packages/flask_registry/registries/appdiscovery.py", line 153, in __init__
self.register(app, ext_name)
File "/usr/local/lib/python2.7/dist-packages/flask_registry/registries/appdiscovery.py", line 163, in register
ext = import_string(ext_name)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/utils.py", line 437, in import_string
sys.exc_info()[2])
File "/usr/local/lib/python2.7/dist-packages/werkzeug/utils.py", line 425, in import_string
module = import_string(module_name)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/utils.py", line 437, in import_string
sys.exc_info()[2])
File "/usr/local/lib/python2.7/dist-packages/werkzeug/utils.py", line 430, in import_string
raise ImportError(e)
werkzeug.utils.ImportStringError: import_string() failed for 'flask_appfactory.ext.jinja2'. Possible reasons are:
- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;
Debugged import:
- 'flask_appfactory' found in '/usr/local/lib/python2.7/dist-packages/flask_appfactory/__init__.pyc'.
- 'flask_appfactory.ext' not found.
Original exception:
ImportStringError: import_string() failed for 'flask_appfactory.ext'. Possible reasons are:
- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;
Debugged import:
- 'flask_appfactory' found in '/usr/local/lib/python2.7/dist-packages/flask_appfactory/__init__.pyc'.
- 'flask_appfactory.ext' not found.
Original exception:
ImportError: 'module' object has no attribute 'ext'
trying to run the server or shell looks the same. Any obvious things I am missing?
Change method signature from:
def appfactory(app_name, module_name, load=True, **kwargs_config):
to
def appfactory(app_name, module_name, load=True, flask_config=None, app_config=None):
In order to support customising the base Flask application (i.e. base_app
).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.