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
"""
Tiny example for using cookies to store user data accross sessions.
"""

from flexx import app, ui, event


class Cookies(ui.Widget):

    def init(self):

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

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


if __name__ == '__main__':
    m = app.launch(Cookies, 'browser')
    app.serve()