I have an application structured almost exactly like the diagram in the docs
here: http://flask.pocoo.org/docs/patterns/packages/#modules-and-resources
Specifically, it looks like:
myapp/
__init__.py
/apps
__init__.py
/audience
__init__.py
views.py
/templates
/campaign
__init__.py
views.py
/templates
/response
__init__.py
views.py
/templates
So in myapp/__init__.py, I have this code:
from flask import Flask
from apps.audience.views import audience
from apps.response.views import response
from apps.campaign.views import campaign
app = Flask(__name__)
app.register_module(audience, url_prefix='/audience')
app.register_module(response, url_prefix='/response')
app.register_module(campaign, url_prefix='/campaign')
And in a view, for example, I have this code:
from flask import Module
audience = Module(__name__)
@audience.route('/')
def index():
return 'Hello audience'
If I have a similar bit of code in the response view like this:
from flask import Module
response = Module(__name__)
@response.route('/')
def index():
return 'Hello response'
All of the assigned urls /audience, /campaign, and /response will return the
same string "Hello campaign" because it seems to be the last in the list
when I am registering the modules. So, my question is, why can't I use the
same method names in the views files if they are separate modules?
Alex
Give name argument in Module like this audience = Module(__name__, name='audience') response = Module(__name__, name='response') Enjoy yourself! 2011/1/26 Alex Ezell <aezell@gmail.com> > I have an application structured almost exactly like the diagram in the > docs here: > http://flask.pocoo.org/docs/patterns/packages/#modules-and-resources > > Specifically, it looks like: > > myapp/ > __init__.py > /apps > __init__.py > /audience > __init__.py > views.py > /templates > /campaign > __init__.py > views.py > /templates > /response > __init__.py > views.py > /templates > > So in myapp/__init__.py, I have this code: > > from flask import Flask > from apps.audience.views import audience > from apps.response.views import response > from apps.campaign.views import campaign > > > app = Flask(__name__) > app.register_module(audience, url_prefix='/audience') > app.register_module(response, url_prefix='/response') > app.register_module(campaign, url_prefix='/campaign') > > And in a view, for example, I have this code: > > from flask import Module > > audience = Module(__name__) > > @audience.route('/') > def index(): > return 'Hello audience' > > If I have a similar bit of code in the response view like this: > > from flask import Module > > response = Module(__name__) > > @response.route('/') > def index(): > return 'Hello response' > > All of the assigned urls /audience, /campaign, and /response will return > the same string "Hello campaign" because it seems to be the last in the list > when I am registering the modules. So, my question is, why can't I use the > same method names in the views files if they are separate modules? > > Alex > >
Thanks! This worked perfectly. I probably should have looked at the API for Module before emailing, but I've learned something new. Alex On Tue, Jan 25, 2011 at 11:21 AM, heww0205 <heww0205@gmail.com> wrote: > Give name argument in Module like this > > audience = Module(__name__, name='audience') > response = Module(__name__, name='response') > > Enjoy yourself! > > > 2011/1/26 Alex Ezell <aezell@gmail.com> > > I have an application structured almost exactly like the diagram in the >> docs here: >> http://flask.pocoo.org/docs/patterns/packages/#modules-and-resources >> >> Specifically, it looks like: >> >> myapp/ >> __init__.py >> /apps >> __init__.py >> /audience >> __init__.py >> views.py >> /templates >> /campaign >> __init__.py >> views.py >> /templates >> /response >> __init__.py >> views.py >> /templates >> >> So in myapp/__init__.py, I have this code: >> >> from flask import Flask >> from apps.audience.views import audience >> from apps.response.views import response >> from apps.campaign.views import campaign >> >> >> app = Flask(__name__) >> app.register_module(audience, url_prefix='/audience') >> app.register_module(response, url_prefix='/response') >> app.register_module(campaign, url_prefix='/campaign') >> >> And in a view, for example, I have this code: >> >> from flask import Module >> >> audience = Module(__name__) >> >> @audience.route('/') >> def index(): >> return 'Hello audience' >> >> If I have a similar bit of code in the response view like this: >> >> from flask import Module >> >> response = Module(__name__) >> >> @response.route('/') >> def index(): >> return 'Hello response' >> >> All of the assigned urls /audience, /campaign, and /response will return >> the same string "Hello campaign" because it seems to be the last in the list >> when I am registering the modules. So, my question is, why can't I use the >> same method names in the views files if they are separate modules? >> >> Alex >> >> > >
I know it's a bit late for you, but I wrote a wee blog today with you in mind. "My take on a Flask Application Skeleton" here http://cols-code-snippets.blogspot.com/2011/02/my-take-on-flask-application-skeleton.html <http://cols-code-snippets.blogspot.com/2011/02/my-take-on-flask-application-skeleton.html> On Tue, Jan 25, 2011 at 6:38 PM, Alex Ezell <aezell@gmail.com> wrote: > Thanks! > > This worked perfectly. I probably should have looked at the API for Module > before emailing, but I've learned something new. > > Alex > > > On Tue, Jan 25, 2011 at 11:21 AM, heww0205 <heww0205@gmail.com> wrote: > >> Give name argument in Module like this >> >> audience = Module(__name__, name='audience') >> response = Module(__name__, name='response') >> >> Enjoy yourself! >> >> >> 2011/1/26 Alex Ezell <aezell@gmail.com> >> >> I have an application structured almost exactly like the diagram in the >>> docs here: >>> http://flask.pocoo.org/docs/patterns/packages/#modules-and-resources >>> >>> Specifically, it looks like: >>> >>> myapp/ >>> __init__.py >>> /apps >>> __init__.py >>> /audience >>> __init__.py >>> views.py >>> /templates >>> /campaign >>> __init__.py >>> views.py >>> /templates >>> /response >>> __init__.py >>> views.py >>> /templates >>> >>> So in myapp/__init__.py, I have this code: >>> >>> from flask import Flask >>> from apps.audience.views import audience >>> from apps.response.views import response >>> from apps.campaign.views import campaign >>> >>> >>> app = Flask(__name__) >>> app.register_module(audience, url_prefix='/audience') >>> app.register_module(response, url_prefix='/response') >>> app.register_module(campaign, url_prefix='/campaign') >>> >>> And in a view, for example, I have this code: >>> >>> from flask import Module >>> >>> audience = Module(__name__) >>> >>> @audience.route('/') >>> def index(): >>> return 'Hello audience' >>> >>> If I have a similar bit of code in the response view like this: >>> >>> from flask import Module >>> >>> response = Module(__name__) >>> >>> @response.route('/') >>> def index(): >>> return 'Hello response' >>> >>> All of the assigned urls /audience, /campaign, and /response will return >>> the same string "Hello campaign" because it seems to be the last in the list >>> when I am registering the modules. So, my question is, why can't I use the >>> same method names in the views files if they are separate modules? >>> >>> Alex >>> >>> >> >> >
I go the other way: In the module: mod = Module(__name__) In the app: app = Flask(__name__) from views.left import mod;app.register_module(mod) from views.right import mod;app.register_module(mod) from views.up import mod;app.register_module(mod) from views.down import mod;app.register_module(mod) On Tue, Jan 25, 2011 at 5:21 PM, heww0205 <heww0205@gmail.com> wrote: > Give name argument in Module like this > > audience = Module(__name__, name='audience') > response = Module(__name__, name='response') > > Enjoy yourself! > > > 2011/1/26 Alex Ezell <aezell@gmail.com> > > I have an application structured almost exactly like the diagram in the >> docs here: >> http://flask.pocoo.org/docs/patterns/packages/#modules-and-resources >> >> Specifically, it looks like: >> >> myapp/ >> __init__.py >> /apps >> __init__.py >> /audience >> __init__.py >> views.py >> /templates >> /campaign >> __init__.py >> views.py >> /templates >> /response >> __init__.py >> views.py >> /templates >> >> So in myapp/__init__.py, I have this code: >> >> from flask import Flask >> from apps.audience.views import audience >> from apps.response.views import response >> from apps.campaign.views import campaign >> >> >> app = Flask(__name__) >> app.register_module(audience, url_prefix='/audience') >> app.register_module(response, url_prefix='/response') >> app.register_module(campaign, url_prefix='/campaign') >> >> And in a view, for example, I have this code: >> >> from flask import Module >> >> audience = Module(__name__) >> >> @audience.route('/') >> def index(): >> return 'Hello audience' >> >> If I have a similar bit of code in the response view like this: >> >> from flask import Module >> >> response = Module(__name__) >> >> @response.route('/') >> def index(): >> return 'Hello response' >> >> All of the assigned urls /audience, /campaign, and /response will return >> the same string "Hello campaign" because it seems to be the last in the list >> when I am registering the modules. So, my question is, why can't I use the >> same method names in the views files if they are separate modules? >> >> Alex >> >> > >