[Tutor] problem with python3.5 headfirst python 2nd ed chpt 10 test drive example decorator issues
Alan Gauld
alan.gauld at yahoo.co.uk
Fri Sep 29 14:59:53 EDT 2017
On 28/09/17 23:35, peter wrote:
> I am on chapter 10 of headfirst python second edition. got most of the
> prior codes to work but am stuck on this one.
I don;t know the book and only vaguely know Flask, but I'd start by
adding some debug print statements to the functions.
Something like
def ....
s = str(session[logged_in])
return s + ...
To see what the actual value is in each call.
> def check_logged_in(func):
> @wraps(func)
> def wrapper(*args, **kwargs):
> if 'logged _in' in session:
> return func(*args, **kwargs)
Maybe try returning session.keys() in this func?
> return 'You are not logged in.'
> return wrapper
>
> @app.route('/')
> def hello() -> str:
> return 'Hello from the simple webapp.'
>
>
> @app.route('/page1')
> @check_logged_in
> def page1():
> return 'this is page 1.'
>
> @app.route('/page2')
> @check_logged_in
> def page2():
> return 'this is page 2.'
>
> @app.route('/page3')
> @check_logged_in
> def page3():
> return 'this is page 3.'
>
>
> @app.route('/login')
> def do_login() -> str:
> session['logged_in'] = True
> return 'you are now logged in.'
>
>
> @app.route('/logout')
> def do_logout() -> str:
> session.pop('logged_in')
> return 'you are now logged out.'
>
> app.secret_key = 'yes'
>
> if __name__ == '__main__':
> app.run(debug=True)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list