def mycookie(request, response): if request.method == 'POST': cooke_key = request.params.get('cooke_key') or 'default' cooke_value = request.params.get('cooke_value') or 'default' response.set_cookie[cooke_key] = cooke_value return response.redirect('/') html = B.HtmlBlock(title='My cookie') grid = B.GridBlock([2, 4, 4, 2]) form = B.FormBlock(action='/', groups=[ dict(label='Cookie Key:', type='text', placeholder='please input key', name='cooke_key'), dict(label='Cookie Value:', type='text', placeholder='please input value', name='cooke_value') ]) view = B.HeadBlock('Request cookie:', center=True) view += '<pre>\n{}\n</pre>'.format(cookie_dumps(request.cookie)) html([ grid(['', form, view, '']), ]) return html
def helloserver(request, response): if request.method == 'POST': return response.jsonify(request.params) html = B.HtmlBlock(title='luckyweb deploy') grid = B.GridBlock([3, 6, 3]) form = B.FormBlock('/', method='post', groups=[ dict(label='Name', type='text', placeholder='please input name text', name='name', row=True), dict(label='Email', type='email', placeholder='please input email', name='email', row=True), dict(label='Password', type='password', placeholder='please input password', name='password', row=True) ]) html(grid(['', form, '']), ) return html
def helloserver(request, response): if request.method == 'POST': location = request.params.get('location') or 'https://www.python.org' return response.redirect(location) html = B.HtmlBlock(title='Redirect') grid = B.GridBlock([4, 4, 4]) form = B.FormBlock('/', method='post', groups=[ {'label': 'Location', 'placeholder': 'input a location, default www.python.org', 'type': 'text', 'name': 'location'}]) html( grid(['', form, '']), ) return html
def helloserver(request, response): if request.method == 'POST': return response.jsonify(request.params) html = B.HtmlBlock(title='Hello lucky server') grid = B.GridBlock([4, 4, 4]) form = B.FormBlock('/', method='post', groups=[ {'label': 'Name', 'type': 'text', 'placeholder': 'please input name text', 'name': 'name'}, {'label': 'Email', 'type': 'email', 'placeholder': 'please input email', 'name': 'email'}, {'label': 'Password', 'type': 'password', 'placeholder': 'please input password', 'name': 'password'}]) img = B.ImgBlock(src='/static/L.png') html( grid(['', form, img]), ) return html
def helloserver(request, response): if request.method == 'POST': filedata = request.data.get('file') filename = filedata.filename filetype = filedata.type content = filedata.file.read().decode() result = '# filename: {}, type: {}\n\n{}'.format( filename, filetype, content) return response.plain(result) html = B.HtmlBlock(title='Upload file') grid = B.GridBlock([4, 4, 4]) form = B.FormBlock('/', method='post', groups=[{ 'label': 'Select text file', 'type': 'file', 'name': 'file' }]) html(grid(['', form, '']), ) return html
def helloblocks(request, response): html = B.HtmlBlock(title='Hello lucky blocks') navbar = B.NavbarBlock( left_items=[ {'href': '/', 'text': 'Lucky Web'}, {'href': '/', 'text': 'Home', 'active': True}, {'href': '#', 'text': 'Article'}, ], right_items=[ {'href': '#', 'text': 'About'}, {'href': '#', 'text': 'Contact us', 'btn': True}, ] ) head_p = B.HeadBlock('PBlock') p = B.PBlock('1234567890qwertyuiop ... zxcvbnm') head_img = B.HeadBlock('ImgBlock') img = B.ImgBlock(src='https://avatars0.githubusercontent.com/u/20847355?s=460&v=4') head_a = B.HeadBlock('ABlock') a = B.ABlock('luckyweb github repository', href='https://github.com/bxtkezhan/luckyweb') head_list = B.HeadBlock('ListBlock', center=True) _list = B.ListBlock([ dict(href='#', text='aaaaaaaaaaaaaaaaaa'), dict(href='#', text='bbbbbbbbbbbbbbbbbb'), dict(href='#', text='cccccccccccccccccc')]) head_table = B.HeadBlock('TableBlock', center=True) table = B.TableBlock([ ['#', 'column 1', 'column 2', 'column 3', 'column 4', 'column 5'], ['1', '5.2', '4.1', '1.5', '0.1', 'setosa'], ['2', '6.0', '2.2', '4.0', '1.0', 'versicolor'], ['3', '4.9', '2.5', '4.5', '1.7', 'virginica']]) head_form = B.HeadBlock('FormBlock', center=True) form = B.FormBlock(action='/', groups=[ {'label': 'Username', 'type': 'text', 'placeholder': 'input username', 'name': 'username'}, {'label': 'Password', 'type': 'password', 'placeholder': 'input password', 'name': 'password'}]) head_card = B.HeadBlock('CardBlock', center=True) card = B.CardBlock('Card header') head_grid = B.HeadBlock('GridBlock', center=True) grid = B.GridBlock([4, 4, 4]) html([ navbar, head_p, p, '<br><hr color="#F00">', head_img, img, '<br><hr color="#F00">', head_a, a, '<br><hr color="#F00">', head_list, _list, '<br><hr color="#F00">', head_table, table, '<br><hr color="#F00">', head_form, form, '<br><hr color="#F00">', head_card, card([ p, img, a]), '<br><hr color="#F00">', head_grid, grid([_list, table, form]) ]) return html