--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
> I want
>
> http://xxx.yyy.com/widget-finder/retrieve/1298
> http://xxx.yyy.com/widget-finder/display&id=146
> http:/xxx.yyy.com/widget-finder/help
> http:/xxx.yyy.com/widget-finder/display&id=146;partno=15
> http:/xxx.yyy.com/widget-finder/search&string=large%20purple%20widget
>
> to do some specific useful things and return relevant content.
>
> If the browser sends something like
>
> http:/xxx.yyy.com/widget-finder/random_junk&xyz=123
>
> which doesn't match any other route decorator, then I want the
> application to respond as if the browser had sent a request for
>
> http://xxx.yyy.com/widget-finder/index.html
>
> Does this make sense?
Can you put a catch-all pattern last to do this?
Mike
Raising exceptions in an error handler is currently not allowed. It is
an implementation detail and we might/should get rid of it, but
currently there is no way to use redirect() (which raises HTTPResponse)
within an error handler. You can, however, manually set the location
header and status code for a redirect (as a workaround):
response.set_header('location', '...')
response.status = 303
> I found this in the release notes for 0.8:
>
> o The default redirect() code changed from 307 to 303.
> o Removed support for @default. Use @error(404) instead.
>
> However, if I run ipython
> import bottle
> app = bottle.Bottle()
>
> help app
>
> redirect doesn't show up in the list of methods.
redirect() is a module-level helper (see static_file() and abort() for
other examples). These are relicts from very early versions of bottle
and might seem counter-intuitive to new users. I'll keep that in mind
and try to find a better, more intuitive API.
> not sure what to make of all this, but having a default route is a
> critical feature for most apps.
The order of routes is significant. They are checked in order. If you
want a catchall route, just add it last. For example: @route('/:#.*#',
method='ANY') matches any request that is not handled by a previous route.
It's been a while, but, can't you do this instead?
> @bottle.route('/')
> @bottle.route('/index.html')
> @bottle.route('/:#.*#',method='ANY')
> def intro_interface():
> stuff
> more stuff
> goodies
Also I believe the proper way is to say:
> @bottle.route('/:#.*#',method='ANY')
> intro_interface # w/o the `()`
The short version of what decorator (i.e., `@blah` thingy) does in
Python is this:
def myfunc():
# blah
def mydecorator(func):
# do something to func
return decorated_func
myfunc = mydecorator(myfunc)
So, instead of a function call `myfunc()`, you pass the function object
`myfunc`, and the decorator returns a function object. When using the
decorator syntax, the above looks like this:
@mydecorator
def myfunc():
# blah
and it does the exact same thing (unless I forgot how to Python).
--
Branko Vukelic
bra...@brankovukelic.com
bra...@herdhound.com
IDEA MACHINE
www.brankovukelic.com
Lead Developer
Herd Hound (tm) - Travel that doesn't bite
www.herdhound.com
Love coffee? You might love Loveffee, too.
loveffee.appspot.com
I plan on using bottle.py as a web framework for an intro-level
programming course. I like the fact that I don't have to use classes
at all and can do simple apps just with functions. So keeping the
"module-level helpers" would be much appreciated. Just my $0.02 of
course. :-D Oh, and note that I wouldn't mind if they were put into a
different module/namespace, I can explain *that* to the students just
fine.
--
Peter H. Froehlich <http://www.cs.jhu.edu/~phf/>
Senior Lecturer | Director, Johns Hopkins Gaming Lab
Be careful: Decorators are applied in reverse order and the catch-all
route is created first in your example.
> Also I believe the proper way is to say:
>> @bottle.route('/:#.*#',method='ANY')
>> intro_interface # w/o the `()`
No, decorators only work with def-blocks. But you can do this:
bottle.route('/:#.*#', method='ANY', callback=intro_interface)
or shorter: bottle.route('/:#.*#', 'ANY', intro_interface)
Hmm? They're already in the "bottle" namespace. You have to do extra
work to bring them into your own namespace.
ie. the difference between:
import bottle
...
bottle.redirect(...)
and:
from bottle import redirect
...
redirect(...)
In my experience, the "from MOD import NAME" syntax is problematic for
various reasons. I always stick to pure "import MOD".
Cheers,
-g
LOL, sorry for the confusion. I meant "if you are about to rip them
out, maybe put them into another namespace instead because I like
using bottle without having to explain classes/objects to my
students". That's all. And yes, I don't teach "from X import Y" at
all. :-D
Bottle is fully backwards compatible for at least one release. Don't
worry :) And I don't plan to remove them, just turn them into shortcuts
for more suitable methods on BaseRequest or Bottle. We'll see.