cookies.pyΒΆ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
Mmmm, cookies ...
Small example for using cookies to (securely) store user data accross sessions.
"""

from flexx import flx


class Cookies(flx.PyComponent):

    def init(self):

        with flx.Widget():
            flx.Label(text='Refreshing the page should '
                           'maintain the value of the line edit.')
            self.edit = flx.LineEdit(placeholder_text='username',
                                     text=self.session.get_cookie('username', ''))

    @flx.reaction('edit.text')
    def _update_cookie(self, *events):
        self.session.set_cookie('username', self.edit.text)


if __name__ == '__main__':
    m = flx.launch(Cookies, 'browser')
    flx.run()