I am trying to use your "Larger Applications" and "Centralized URL Map"
patterns, but can't make it work. I get BuildError("frontend.hello",{},None)
when using url_for('frontend.hello').
Can you give me a full example of how to combine the 2 patterns with
url_for?
Thanks for your help.
Chili
Hi, You give a lot of information so this is a wild stab in the dark. If you are using Module inside views.py then all your modules are named 'views' because that is what the module is named when you use Module from within views.py. To get around this you use it like this inside views.py: frontend = Module(__name__,'frontend') then all your url_for and template inheritance should work. This is what bit me in the behind when I was just starting out, so maybe this is your problem too? 2011/1/15 Imad <chiliconsql@gmail.com> > I am trying to use your "Larger Applications" and "Centralized URL Map" > patterns, but can't make it work. I get BuildError("frontend.hello",{},None) > when using url_for('frontend.hello'). > Can you give me a full example of how to combine the 2 patterns with > url_for? > > Thanks for your help. > > Chili > -- Best regards Mathias Nielsen cohida.com (website currently under reconstruction) (0045)61264334
Mathias,
Sorry for the vagueness of my question and lack of details, here's a better
description:
I have the following structure
/test
/runserver.py
/quick
/__init__.py
/views
/__init__.py (empty)
/admin.py
/frontend.py
/templates
/hello.html
### Code for /test/runserver.py :
from quick import app
app.run(debug=True)
### END Code for /test/runserver.py
### Code for /quick/__init__.py ::
from flask import Flask
app = Flask(__name__)
# import and register the modules as shown in
http://flask.pocoo.org/docs/patterns/packages/#working-with-modules
from quick.views.frontend import frontend
from quick.views.admin import admin
app.register_module(frontend)
app.register_module(admin, url_prefix='/admin')
#add rules as shown in
http://flask.pocoo.org/docs/patterns/lazyloading/#converting-to-centralized-url-map
app.add_url_rule('/', view_func=views.frontend.index)
app.add_url_rule('/hello', view_func=views.frontend.hello)
app.add_url_rule('/admin/login', view_func=views.admin.login)
app.add_url_rule('/hello/<uname>', view_func=views.frontend.hello)
### END Code /quick/__init__.py ::
### Code for /quick/views/admin.py ::
from flask import Module
admin = Module(__name__, 'admin')
def login():
return 'Try to log in'
### END Code /quick/views/admin.py ::
### Code for /quick/views/frontend.py ::
from flask import render_template, Module
frontend = Module(__name__, 'frontend')
def index():
return 'Index Page'
def hello(uname='World'):
return render_template('hello.html', name=uname)
### END Code /quick/views/frontend.py ::
### Code for /quick/templates/hello.py ::
<!doctype html>
<title>Hello from Flask</title>
<h1>Hello {{ name }}!</h1>
<a href="{{ url_for('frontend.hello') }}">Home</a>
<a href="{{ url_for('admin.login') }}">Log In</a>
### END Code /quick/templates/hello.py ::
This causes the error: <BuildError: ('frontend.hello', {}, None) > when I
try to access /hello
The code works fine if I use the @admin.route and @frontend.route decorators
in the view modules, so I don't understand why the above code doesn't work
when the decorator mainly calls add_url_rule()
Changing app.add_url_rule to frontend.add_url_rule generates a "Page Not
Found" error
What am I doing wrong?
On Tue, Jan 18, 2011 at 9:20 AM, Mathias Nielsen <mhn@cohida.com> wrote:
> Hi,
> You give a lot of information so this is a wild stab in the dark.
> If you are using Module inside views.py then all your modules are named
> 'views' because that is what the module is named when you use Module from
> within views.py.
> To get around this you use it like this inside views.py:
>
> frontend = Module(__name__,'frontend')
>
> then all your url_for and template inheritance should work.
>
> This is what bit me in the behind when I was just starting out, so maybe
> this is your problem too?
>
> 2011/1/15 Imad <chiliconsql@gmail.com>
>
> I am trying to use your "Larger Applications" and "Centralized URL Map"
>> patterns, but can't make it work. I get BuildError("frontend.hello",{},None)
>> when using url_for('frontend.hello').
>> Can you give me a full example of how to combine the 2 patterns with
>> url_for?
>>
>> Thanks for your help.
>>
>> Chili
>>
>
>
>
> --
> Best regards
>
> Mathias Nielsen
> cohida.com (website currently under reconstruction)
> (0045)61264334
>
I have no experience with the centralized url map in Flask, but I have just
tried adding app.add_url_rule to my own project and it works.
I am sure its just a typo in your mail, but just to be sure. Are you
importing the views module in your __init__.py? (from quick import views)
Or since its a module, maybe it should be
from quick.views import frontend
app.add_url_rule('/hello', view_func=frontend.hello)
If thats not it, then I have no idea.
Lets hope someone else here have a better solution for you.
2011/1/20 ChiliConSQL <chiliconsql@gmail.com>
> Mathias,
> Sorry for the vagueness of my question and lack of details, here's a better
> description:
>
> I have the following structure
> /test
> /runserver.py
> /quick
> /__init__.py
> /views
> /__init__.py (empty)
> /admin.py
> /frontend.py
> /templates
> /hello.html
>
> ### Code for /test/runserver.py :
>
> from quick import app
> app.run(debug=True)
>
> ### END Code for /test/runserver.py
>
> ### Code for /quick/__init__.py ::
>
> from flask import Flask
> app = Flask(__name__)
> # import and register the modules as shown in
> http://flask.pocoo.org/docs/patterns/packages/#working-with-modules
> from quick.views.frontend import frontend
> from quick.views.admin import admin
>
> app.register_module(frontend)
> app.register_module(admin, url_prefix='/admin')
>
> #add rules as shown in
>
http://flask.pocoo.org/docs/patterns/lazyloading/#converting-to-centralized-url-map
> app.add_url_rule('/', view_func=views.frontend.index)
> app.add_url_rule('/hello', view_func=views.frontend.hello)
> app.add_url_rule('/admin/login', view_func=views.admin.login)
> app.add_url_rule('/hello/<uname>', view_func=views.frontend.hello)
>
> ### END Code /quick/__init__.py ::
>
> ### Code for /quick/views/admin.py ::
>
> from flask import Module
> admin = Module(__name__, 'admin')
>
> def login():
> return 'Try to log in'
>
> ### END Code /quick/views/admin.py ::
>
> ### Code for /quick/views/frontend.py ::
>
> from flask import render_template, Module
> frontend = Module(__name__, 'frontend')
>
> def index():
> return 'Index Page'
>
> def hello(uname='World'):
> return render_template('hello.html', name=uname)
>
> ### END Code /quick/views/frontend.py ::
>
> ### Code for /quick/templates/hello.py ::
>
> <!doctype html>
> <title>Hello from Flask</title>
> <h1>Hello {{ name }}!</h1>
> <a href="{{ url_for('frontend.hello') }}">Home</a>
> <a href="{{ url_for('admin.login') }}">Log In</a>
>
> ### END Code /quick/templates/hello.py ::
> This causes the error: <BuildError: ('frontend.hello', {}, None) > when I
> try to access /hello
> The code works fine if I use the @admin.route and @frontend.route
> decorators in the view modules, so I don't understand why the above code
> doesn't work when the decorator mainly calls add_url_rule()
> Changing app.add_url_rule to frontend.add_url_rule generates a "Page Not
> Found" error
> What am I doing wrong?
>
>
> On Tue, Jan 18, 2011 at 9:20 AM, Mathias Nielsen <mhn@cohida.com> wrote:
>
>> Hi,
>> You give a lot of information so this is a wild stab in the dark.
>> If you are using Module inside views.py then all your modules are named
>> 'views' because that is what the module is named when you use Module from
>> within views.py.
>> To get around this you use it like this inside views.py:
>>
>> frontend = Module(__name__,'frontend')
>>
>> then all your url_for and template inheritance should work.
>>
>> This is what bit me in the behind when I was just starting out, so maybe
>> this is your problem too?
>>
>> 2011/1/15 Imad <chiliconsql@gmail.com>
>>
>> I am trying to use your "Larger Applications" and "Centralized URL Map"
>>> patterns, but can't make it work. I get BuildError("frontend.hello",{},None)
>>> when using url_for('frontend.hello').
>>> Can you give me a full example of how to combine the 2 patterns with
>>> url_for?
>>>
>>> Thanks for your help.
>>>
>>> Chili
>>>
>>
>>
>>
>> --
>> Best regards
>>
>> Mathias Nielsen
>> cohida.com (website currently under reconstruction)
>> (0045)61264334
>>
>
>
--
Best regards
Mathias Nielsen
cohida.com (website currently under reconstruction)
(0045)61264334
I am importing the modules in lines 4 and 5. Remember I don't have just 1 views.py module, but 2 separate module files in a views folder. If I combine the modules into 1 views.py file, then everything works as it is supposed to, On Thu, Jan 20, 2011 at 2:09 AM, Mathias Nielsen <mhn@cohida.com> wrote: > I have no experience with the centralized url map in Flask, but I have just > tried adding app.add_url_rule to my own project and it works. > > I am sure its just a typo in your mail, but just to be sure. Are you > importing the views module in your __init__.py? (from quick import views) > Or since its a module, maybe it should be > > from quick.views import frontend > > app.add_url_rule('/hello', view_func=frontend.hello) > > If thats not it, then I have no idea. > > Lets hope someone else here have a better solution for you. > > > > 2011/1/20 ChiliConSQL <chiliconsql@gmail.com> > > Mathias, >> Sorry for the vagueness of my question and lack of details, here's a >> better description: >> >> I have the following structure >> /test >> /runserver.py >> /quick >> /__init__.py >> /views >> /__init__.py (empty) >> /admin.py >> /frontend.py >> /templates >> /hello.html >> >> ### Code for /test/runserver.py : >> >> from quick import app >> app.run(debug=True) >> >> ### END Code for /test/runserver.py >> >> ### Code for /quick/__init__.py :: >> >> from flask import Flask >> app = Flask(__name__) >> # import and register the modules as shown in >> http://flask.pocoo.org/docs/patterns/packages/#working-with-modules >> from quick.views.frontend import frontend >> from quick.views.admin import admin >> >> app.register_module(frontend) >> app.register_module(admin, url_prefix='/admin') >> >> #add rules as shown in >> http://flask.pocoo.org/docs/patterns/lazyloading/#converting-to-centralized-url-map >> app.add_url_rule('/', view_func=views.frontend.index) >> app.add_url_rule('/hello', view_func=views.frontend.hello) >> app.add_url_rule('/admin/login', view_func=views.admin.login) >> app.add_url_rule('/hello/<uname>', view_func=views.frontend.hello) >> >> ### END Code /quick/__init__.py :: >> >> ### Code for /quick/views/admin.py :: >> >> from flask import Module >> admin = Module(__name__, 'admin') >> >> def login(): >> return 'Try to log in' >> >> ### END Code /quick/views/admin.py :: >> >> ### Code for /quick/views/frontend.py :: >> >> from flask import render_template, Module >> frontend = Module(__name__, 'frontend') >> >> def index(): >> return 'Index Page' >> >> def hello(uname='World'): >> return render_template('hello.html', name=uname) >> >> ### END Code /quick/views/frontend.py :: >> >> ### Code for /quick/templates/hello.py :: >> >> <!doctype html> >> <title>Hello from Flask</title> >> <h1>Hello {{ name }}!</h1> >> <a href="{{ url_for('frontend.hello') }}">Home</a> >> <a href="{{ url_for('admin.login') }}">Log In</a> >> >> ### END Code /quick/templates/hello.py :: >> This causes the error: <BuildError: ('frontend.hello', {}, None) > when I >> try to access /hello >> The code works fine if I use the @admin.route and @frontend.route >> decorators in the view modules, so I don't understand why the above code >> doesn't work when the decorator mainly calls add_url_rule() >> Changing app.add_url_rule to frontend.add_url_rule generates a "Page Not >> Found" error >> What am I doing wrong? >> >> >> On Tue, Jan 18, 2011 at 9:20 AM, Mathias Nielsen <mhn@cohida.com> wrote: >> >>> Hi, >>> You give a lot of information so this is a wild stab in the dark. >>> If you are using Module inside views.py then all your modules are named >>> 'views' because that is what the module is named when you use Module from >>> within views.py. >>> To get around this you use it like this inside views.py: >>> >>> frontend = Module(__name__,'frontend') >>> >>> then all your url_for and template inheritance should work. >>> >>> This is what bit me in the behind when I was just starting out, so maybe >>> this is your problem too? >>> >>> 2011/1/15 Imad <chiliconsql@gmail.com> >>> >>> I am trying to use your "Larger Applications" and "Centralized URL Map" >>>> patterns, but can't make it work. I get BuildError("frontend.hello",{},None) >>>> when using url_for('frontend.hello'). >>>> Can you give me a full example of how to combine the 2 patterns with >>>> url_for? >>>> >>>> Thanks for your help. >>>> >>>> Chili >>>> >>> >>> >>> >>> -- >>> Best regards >>> >>> Mathias Nielsen >>> cohida.com (website currently under reconstruction) >>> (0045)61264334 >>> >> >> > > > -- > Best regards > > Mathias Nielsen > cohida.com (website currently under reconstruction) > (0045)61264334 >
Hi there, does anyone have experience with deploying an Flask-App with ruby-passenger? Thanks, r.
On Wed, Jan 19, 2011 at 10:14 AM, rocco storm <roccostorm@gmx.de> wrote: > Hi there, > > does anyone have experience with deploying an Flask-App with ruby-passenger? > > Thanks, > r. > Phusion Passenger will run WSGI applications, but it's little more than a proof-of-concept. I do not recommend it: when I last tried it, there wasn't any kind of error logging for WSGI applications.
I'd expect not. Perhaps look into mod_wsgi. On 19 January 2011 15:14, rocco storm <roccostorm@gmx.de> wrote: > Hi there, > > does anyone have experience with deploying an Flask-App with > ruby-passenger? > > Thanks, > r. >