tailieunhanh - Web to py enterprise web framework - p 8

FORM SELF-SUBMISSION 55 1 2 3 4 5 6 7 def first(): form = FORM(INPUT(_name='visitor_name', requires=IS_NOT_EMPTY()), INPUT(_type='submit')) if (, session): = redirect(URL(r=request, f='second')) return dict(form=form) where we are saying that the FORM tag contains two INPUT tags. The attributes of the input tags are specified by the named arguments starting with underscore. The requires argument is not a tag attribute (because it does not start by underscore) but it sets a validator for the value of visitor name. The form object can be easily serialized in HTML by embedding it in the "default/" view. 1 2 3 {{extend ''}} What is your name? {{=form}} The. | FORM SELF-SUBMISSION 55 1 2 3 4 5 6 7 1 2 3 def first form FORM INPUT _name visitor_name requires IS_NOT_EMPTY INPUT _type submit if session redirect URL r request f second return dict form form where we are saying that the FORM tag contains two INPUT tags. The attributes of the input tags are specified by the named arguments starting with underscore. The requires argument is not a tag attribute because it does not start by underscore but it sets a validator for the value of visitor_name. The form object can be easily serialized in HTML by embedding it in the default view. extend What is your name form The method applies the validators. If the self-submitted form passes validation it stores the variables in the session and redirects as before. If the form does not pass validation error messages are inserted in the form and shown to the user shown below In the next section we will show how forms can be generated automatically from a model. 56 OVERVIEW An Image Blog Here as another example we wish to create a web application that allows the administrator to post images and give them a name and allows the visitors of the web site to view the images and submit comments. As before create the new application from the site page in admin and navigate to the EDIT page We start by creating a model a representation of the persistent data in the application the images to upload their names and the comments . First you need to create edit a model file which for lack of imagination we call . Models and controllers must have a .py extension since they are Python code. If the extension is not provided it is appended by WEB2py. Views instead have a .html extension since they mainly contain HTML code. Edit the file by clicking the corresponding edit button 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 AN IMAGE BLOG 57 and enter the following db DAL sqlite

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.