librelist archives

« back to archive

Multiple apps with flask-actions

Multiple apps with flask-actions

From:
Jair Gaxiola
Date:
2011-07-08 @ 02:14
Hi,

I have my project with two apps (api, instances) using flash-actions,
I need  load all apps from manage.py but I dont know like. My
manage.py

#!/usr/bin/env python2
# -*- encoding:utf-8 -*-

from flask import Flask
from flaskext.actions import Manager
import settings
#from api import app
from instances import app

app.config.from_object(settings)
manager = Manager(app)

if __name__ == "__main__":
    manager.run()

Now, only load app instance. How can load all apps?

-- 
SIN ETIQUETAS.[ PUNTO ]
http://flavors.me/jyr
http://pythoncocoa.com
http://opentumblr.com

回复: [flask] Multiple apps with flask-actions

From:
Young King
Date:
2011-07-08 @ 03:03
 You should use the flask module package or the new flask blueprints.
And register them as two modules.like this:

# example/__init__.py

def create_app(config=None):
    app = Flask(__name__)
    if config:
        app.config.from_object(config)
    db.init_app(app)
    app.register_module(api)
    app.register_module(instances)
    return app

# mange.py

from flaskext.actions import Manager
import settings
from example import  create_app

   app = create_app(settings)
   manager = Manager(app)

if __name__ == "__main__":
   manager.run()












-- 
YoungKing
Sent with Sparrow <http://bit.ly/sigsprw>
已使用 Sparrow <http://www.sparrowmailapp.com/?sig> 发送

在 2011年7月8日星期五,上午10:14,Jair Gaxiola 写道:

Hi,

I have my project with two apps (api, instances) using flash-actions,
I need load all apps from manage.py but I dont know like. My
manage.py

#!/usr/bin/env python2
# -*- encoding:utf-8 -*-

from flask import Flask
from flaskext.actions import Manager
import settings
#from api import app
from instances import app

app.config.from_object(settings)
manager = Manager(app)

if __name__ == "__main__":
manager.run()

Now, only load app instance. How can load all apps?

-- 
SIN ETIQUETAS.[ PUNTO ]
http://flavors.me/jyr
http://pythoncocoa.com
http://opentumblr.com

Re: 回复: [flask] Multiple apps with flask-actio

From:
Jair Gaxiola
Date:
2011-07-08 @ 05:32
On Thu, Jul 7, 2011 at 10:03 PM, Young King <yanckin@gmail.com> wrote:
> You should use the flask module package or the new flask blueprints.
> And register them as two modules.like this:
> # example/__init__.py
> def create_app(config=None):
>     app = Flask(__name__)
>     if config:
>         app.config.from_object(config)
>     db.init_app(app)

How can import db?

-- 
SIN ETIQUETAS.[ PUNTO ]
http://flavors.me/jyr
http://pythoncocoa.com
http://opentumblr.com

回复: [flask] Multiple apps with flask-actio

From:
YoungKing
Date:
2011-07-08 @ 05:47
It's just a snippet extract from my code ,the `db` is used with 
Flask-SQLAlchemy,you don't really need it.

-- 
YoungKing
Sent with Sparrow (http://bit.ly/sigsprw)
已使用 Sparrow (http://www.sparrowmailapp.com/?sig) 发送 

在 2011年7月8日星期五,下午1:32,Jair Gaxiola 写道:

> On Thu, Jul 7, 2011 at 10:03 PM, Young King <yanckin@gmail.com 
(mailto:yanckin@gmail.com)> wrote:
> > You should use the flask module package or the new flask blueprints.
> > And register them as two modules.like this:
> > # example/__init__.py
> > def create_app(config=None):
> > app = Flask(__name__)
> > if config:
> > app.config.from_object(config)
> > db.init_app(app)
> 
> How can import db?
> 
> -- 
> SIN ETIQUETAS.[ PUNTO ]
> http://flavors.me/jyr
> http://pythoncocoa.com
> http://opentumblr.com

Re: 回复: [flask] Multiple apps with flask-actio

From:
Jair Gaxiola
Date:
2011-07-08 @ 05:56
On Fri, Jul 8, 2011 at 12:47 AM, YoungKing <yanckin@gmail.com> wrote:
> It's just a snippet extract from my code ,the `db` is used with
> Flask-SQLAlchemy,you don't really need it.
>

Ok, I have manage.py with

from flask import Flask
from flaskext.actions import Manager
from register import apps

import settings

app = apps(settings)
manager = Manager(app)

if __name__ == "__main__":
    manager.run()


register/__init__.py with

from flask import Flask
from api.views.frontend import api
from instances.views.frontend import instances

def apps(config = None):
  app = Flask(__name__)

  if config:
    app.config.from_object(config)

  app.register_module(instances)

  return app

my api app with

from flask import Module

api = Module(__name__)

@api.route('/')
def index():
    return "Api"

and instance app with:

from flask import Module

instances = Module(__name__)

@instances.route('/')
def index():
    return "Instances"


but return the error

./register/__init__.py:11: DeprecationWarning: Modules are deprecated.
 Upgrade to using blueprints.  Have a look into the documentation for
more information.  If this module was registered by a Flask-Extension
upgrade the extension or contact the author of that extension instead.
 (Registered <flask.module.Module object at 0x101b5be10>)
  app.register_module(api)
./register/__init__.py:12: DeprecationWarning: Modules are deprecated.
 Upgrade to using blueprints.  Have a look into the documentation for
more information.  If this module was registered by a Flask-Extension
upgrade the extension or contact the author of that extension instead.
 (Registered <flask.module.Module object at 0x101b60410>)
  app.register_module(instances)
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    app = apps(settings)
  File "./register/__init__.py", line 12, in apps
    app.register_module(instances)
  File 
"/Applications/MNPP/Library/python26/lib/python2.6/site-packages/Flask-0.7.1_devdev_20110704-py2.6.egg/flask/app.py",
line 634, in register_module
    self.register_blueprint(module, **options)
  File 
"/Applications/MNPP/Library/python26/lib/python2.6/site-packages/Flask-0.7.1_devdev_20110704-py2.6.egg/flask/app.py",
line 647, in register_blueprint
    (blueprint, self.blueprints[blueprint.name], blueprint.name)
AssertionError: A blueprint's name collision ocurred between
<flask.module.Module object at 0x101b60410> and <flask.module.Module
object at 0x101b5be10>.  Both share the same name "frontend".
Blueprints that are created on the fly need unique names.

Any suggestions?


-- 
SIN ETIQUETAS.[ PUNTO ]
http://flavors.me/jyr
http://pythoncocoa.com
http://opentumblr.com

Re: 回复: [flask] Multiple apps with flask-actio

From:
Jair Gaxiola
Date:
2011-07-08 @ 06:17
On Fri, Jul 8, 2011 at 12:56 AM, Jair Gaxiola <jyr.gaxiola@gmail.com> wrote:
> On Fri, Jul 8, 2011 at 12:47 AM, YoungKing <yanckin@gmail.com> wrote:
>> It's just a snippet extract from my code ,the `db` is used with
>> Flask-SQLAlchemy,you don't really need it.
>>
>
> Ok, I have manage.py with
>
> from flask import Flask
> from flaskext.actions import Manager
> from register import apps
>
> import settings
>
> app = apps(settings)
> manager = Manager(app)
>
> if __name__ == "__main__":
>    manager.run()
>
>
> register/__init__.py with
>
> from flask import Flask
> from api.views.frontend import api
> from instances.views.frontend import instances
>
> def apps(config = None):
>  app = Flask(__name__)
>
>  if config:
>    app.config.from_object(config)
>
>  app.register_module(instances)
>
>  return app
>
> my api app with
>
> from flask import Module
>
> api = Module(__name__)
>
> @api.route('/')
> def index():
>    return "Api"
>
> and instance app with:
>
> from flask import Module
>
> instances = Module(__name__)
>
> @instances.route('/')
> def index():
>    return "Instances"
>
>
> but return the error
>
> ./register/__init__.py:11: DeprecationWarning: Modules are deprecated.
>  Upgrade to using blueprints.  Have a look into the documentation for
> more information.  If this module was registered by a Flask-Extension
> upgrade the extension or contact the author of that extension instead.
>  (Registered <flask.module.Module object at 0x101b5be10>)
>  app.register_module(api)
> ./register/__init__.py:12: DeprecationWarning: Modules are deprecated.
>  Upgrade to using blueprints.  Have a look into the documentation for
> more information.  If this module was registered by a Flask-Extension
> upgrade the extension or contact the author of that extension instead.
>  (Registered <flask.module.Module object at 0x101b60410>)
>  app.register_module(instances)
> Traceback (most recent call last):
>  File "./manage.py", line 10, in <module>
>    app = apps(settings)
>  File "./register/__init__.py", line 12, in apps
>    app.register_module(instances)
>  File 
"/Applications/MNPP/Library/python26/lib/python2.6/site-packages/Flask-0.7.1_devdev_20110704-py2.6.egg/flask/app.py",
> line 634, in register_module
>    self.register_blueprint(module, **options)
>  File 
"/Applications/MNPP/Library/python26/lib/python2.6/site-packages/Flask-0.7.1_devdev_20110704-py2.6.egg/flask/app.py",
> line 647, in register_blueprint
>    (blueprint, self.blueprints[blueprint.name], blueprint.name)
> AssertionError: A blueprint's name collision ocurred between
> <flask.module.Module object at 0x101b60410> and <flask.module.Module
> object at 0x101b5be10>.  Both share the same name "frontend".
> Blueprints that are created on the fly need unique names.
>
> Any suggestions?
>

Ok, I can't have two files with same name

from api.views.frontend import api
from instances.views.frontend import instances

so, delete __init__.py of api and instance apps, example

api/__init__.py
instances/__init__.py

Now, works me

from api.views.frontend import api
from instances.views.frontend import instances

It's right to do this?


-- 
SIN ETIQUETAS.[ PUNTO ]
http://flavors.me/jyr
http://pythoncocoa.com
http://opentumblr.com