Another issue in upgrading to 0.7 is that some pagination code I have is
resulting in a redirect loop now:
@admins.route('/admins/', defaults={'page': 1})
@admins.route('/admins/<int:page>/')
def list(page):
pagination = Admin.query.paginate(page=page, per_page=5)
return render_template('admin_list.html', pagination=pagination)
This seems to redirect infinitely between /admins/ and /admins/1/
This was working nicely in 0.6.1
Hi, On 6/29/11 6:04 PM, Charlie Evett wrote: > Another issue in upgrading to 0.7 is that some pagination code I have is > resulting in a redirect loop now: > > @admins.route('/admins/', defaults={'page': 1}) > @admins.route('/admins/<int:page>/') > def list(page): > pagination = Admin.query.paginate(page=page, per_page=5) > return render_template('admin_list.html', pagination=pagination) > > This seems to redirect infinitely between /admins/ and /admins/1/ A small change in the internal code surfaced a bug in Werkzeug 0.7. The Flask 0.7.1 release which I just pushed out works around that for the time being. Regards, Armin
Hey,
I have something to update to this. Not only this, but another bug has
surfaced.
If I try,
@route('/verify')
@route('/verify/<token>')
def verify(token=None):
This thing redirects me to /verify/None which it clearly should NOT. It
should handle the request without redirection and assume token to be None
(NoneType not unicode). I tried to debug and find type of token once it
redirected ot /verify/None and as expected, it turned out to be unicode.
Am I doing something wrong or has something broken/changed?
On 29 June 2011 22:08, Armin Ronacher <armin.ronacher@active-4.com> wrote:
> Hi,
>
> On 6/29/11 6:04 PM, Charlie Evett wrote:
> > Another issue in upgrading to 0.7 is that some pagination code I have is
> > resulting in a redirect loop now:
> >
> > @admins.route('/admins/', defaults={'page': 1})
> > @admins.route('/admins/<int:page>/')
> > def list(page):
> > pagination = Admin.query.paginate(page=page, per_page=5)
> > return render_template('admin_list.html', pagination=pagination)
> >
> > This seems to redirect infinitely between /admins/ and /admins/1/
> A small change in the internal code surfaced a bug in Werkzeug 0.7. The
> Flask 0.7.1 release which I just pushed out works around that for the
> time being.
>
>
> Regards,
> Armin
>
--
Regards,
Ishbir Singh
Hi, On 7/9/11 4:22 PM, Ishbir Singh wrote: > I have something to update to this. Not only this, but another bug has > surfaced. Not a bug, expected behavior. > This thing redirects me to /verify/None which it clearly should NOT. It > should handle the request without redirection and assume token to be > None (NoneType not unicode). I tried to debug and find type of token > once it redirected ot /verify/None and as expected, it turned out to be > unicode. It should. If you have routes like this you need to inform the routing system of your defaults: @app.route('/verify', defaults={'token': None}) @app.route('/verify/<token>') def verify(token): ... > Am I doing something wrong or has something broken/changed? Routing in Werkzeug before 0.7 was kinda flanky and sometimes seems to have worked when in fact it was deep in undefined behavior. If you upgrade to the soon to be released Werkzeug 0.7 you will find much more reliable behavior which should not magically change on update :) Regards, Armin
Hey,
So as you suggested, I changed it to this-
@app.route('/verify', defaults={'token': None})
@app.route('/verify/<token>')
But, this thing still redirects me to /verify/None. You say this is expected
behaviour.. any way to change this?
On 9 July 2011 20:23, Armin Ronacher <armin.ronacher@active-4.com> wrote:
> Hi,
>
> On 7/9/11 4:22 PM, Ishbir Singh wrote:
> > I have something to update to this. Not only this, but another bug has
> > surfaced.
> Not a bug, expected behavior.
>
> > This thing redirects me to /verify/None which it clearly should NOT. It
> > should handle the request without redirection and assume token to be
> > None (NoneType not unicode). I tried to debug and find type of token
> > once it redirected ot /verify/None and as expected, it turned out to be
> > unicode.
> It should. If you have routes like this you need to inform the routing
> system of your defaults:
>
> @app.route('/verify', defaults={'token': None})
> @app.route('/verify/<token>')
> def verify(token):
> ...
>
> > Am I doing something wrong or has something broken/changed?
> Routing in Werkzeug before 0.7 was kinda flanky and sometimes seems to
> have worked when in fact it was deep in undefined behavior. If you
> upgrade to the soon to be released Werkzeug 0.7 you will find much more
> reliable behavior which should not magically change on update :)
>
>
> Regards,
> Armin
>
--
Regards,
Ishbir Singh
Hi, On 7/9/11 4:58 PM, Ishbir Singh wrote: > But, this thing still redirects me to /verify/None. You say this is > expected behaviour.. any way to change this? Are you sure you're using Flask 0.7.1 or 0.7.2? Because I cannot reproduce that: >>> from flask import Flask >>> app = Flask(__name__) >>> >>> @app.route('/verify', defaults={'token': None}) ... @app.route('/verify/<token>') ... def verify(token): ... return token or 'no token' ... >>> c = app.test_client() >>> c.get('/verify').data 'no token' >>> c.get('/verify/awesome').data 'awesome' Regards, Armin
I can't seem to reproduce that either. For similar situations, I usually add
a '/' to the end of the path.
Try this:
@route('/verify/') # <-- Notice the '/' on the end of the path
@route('/verify/<token>')
def verify(token=None):
That'll redirect a '/verify' path to '/verify/' but that should be fine for
what you're trying to do.
On Sat, Jul 9, 2011 at 11:38 AM, Armin Ronacher <armin.ronacher@active-4.com
> wrote:
> Hi,
>
> On 7/9/11 4:58 PM, Ishbir Singh wrote:
> > But, this thing still redirects me to /verify/None. You say this is
> > expected behaviour.. any way to change this?
> Are you sure you're using Flask 0.7.1 or 0.7.2? Because I cannot
> reproduce that:
>
> >>> from flask import Flask
> >>> app = Flask(__name__)
> >>>
> >>> @app.route('/verify', defaults={'token': None})
> ... @app.route('/verify/<token>')
> ... def verify(token):
> ... return token or 'no token'
> ...
> >>> c = app.test_client()
> >>> c.get('/verify').data
> 'no token'
> >>> c.get('/verify/awesome').data
> 'awesome'
>
>
> Regards,
> Armin
>
Hey, Okay, sorry! The error was due to my browser's cache. I tried using curl and it give me the right response. Thank you for your time! On 9 July 2011 22:40, Joe Esposito <espo58@gmail.com> wrote: > I can't seem to reproduce that either. For similar situations, I usually > add a '/' to the end of the path. > > Try this: > > @route('/verify/') # <-- Notice the '/' on the end of the path > @route('/verify/<token>') > def verify(token=None): > > That'll redirect a '/verify' path to '/verify/' but that should be fine for > what you're trying to do. > > On Sat, Jul 9, 2011 at 11:38 AM, Armin Ronacher < > armin.ronacher@active-4.com> wrote: > >> Hi, >> >> On 7/9/11 4:58 PM, Ishbir Singh wrote: >> > But, this thing still redirects me to /verify/None. You say this is >> > expected behaviour.. any way to change this? >> Are you sure you're using Flask 0.7.1 or 0.7.2? Because I cannot >> reproduce that: >> >> >>> from flask import Flask >> >>> app = Flask(__name__) >> >>> >> >>> @app.route('/verify', defaults={'token': None}) >> ... @app.route('/verify/<token>') >> ... def verify(token): >> ... return token or 'no token' >> ... >> >>> c = app.test_client() >> >>> c.get('/verify').data >> 'no token' >> >>> c.get('/verify/awesome').data >> 'awesome' >> >> >> Regards, >> Armin >> > > -- Regards, Ishbir Singh
@admins.route('/admins/<int:page>/')
def list(page=1):
This should work better
On Wed, Jun 29, 2011 at 11:04 AM, Charlie Evett <charlieevett@litl.com>wrote:
> Another issue in upgrading to 0.7 is that some pagination code I have is
> resulting in a redirect loop now:
>
> @admins.route('/admins/', defaults={'page': 1})
> @admins.route('/admins/<int:page>/')
> def list(page):
> pagination = Admin.query.paginate(page=page, per_page=5)
> return render_template('admin_list.html', pagination=pagination)
>
> This seems to redirect infinitely between /admins/ and /admins/1/
>
> This was working nicely in 0.6.1
>
Thanks.
If I have:
@admins.route('/admins/<int:page>/')
@admins.route('/admins/')
def list(page=1):
pagination = Admin.query.paginate(page=page, per_page=5)
return render_template('admin_list.html', pagination=pagination)
It works as previously
On Wed, Jun 29, 2011 at 12:11 PM, Adam Patterson <fakeempire@gmail.com>wrote:
> @admins.route('/admins/<int:page>/')
> def list(page=1):
>
> This should work better
>
> On Wed, Jun 29, 2011 at 11:04 AM, Charlie Evett <charlieevett@litl.com>wrote:
>
>> Another issue in upgrading to 0.7 is that some pagination code I have is
>> resulting in a redirect loop now:
>>
>> @admins.route('/admins/', defaults={'page': 1})
>> @admins.route('/admins/<int:page>/')
>> def list(page):
>> pagination = Admin.query.paginate(page=page, per_page=5)
>> return render_template('admin_list.html', pagination=pagination)
>>
>> This seems to redirect infinitely between /admins/ and /admins/1/
>>
>> This was working nicely in 0.6.1
>>
>
>