7. The View
- The view or template must have the same name as the function definition in the controller.
- In the admin tool you can create html templates. If they are called from the
default.py
controller, make sure that you preface the template name with "default/"
- Line 1 includes the file
layout.html
which has references to css, jQuery, and Bootstrap files, as well as configurable page layout options. - Line 2 is the reference to the grid object defined in the controller. Web2py uses pure Python for templates. You don't have to learn a different templating language. Python code in templates is delimited with
{{ }}
. {{=grid}}
outputs the serialized grid object to the screen. - Templates default to the extension of
.html
.
##### Copy and paste the code below into default/manage_aliases.html #####
{{extend 'layout.html'}}
{{=grid}}
- The full path to the template is shown below.
https://milesm.pythonanywhere.com/aliaser/default/manage_aliases
aliaser
is the application name.default
is the controller name (default.py
)manage_aliases
is the view (manage_aliases.html
)- When we point our browser to this address, the first thing we see is a login screen.
- The reason for this is, when we defined the controller definition we decorated it with:
@auth.requires_membership('manager')
- This means that the user must be registered and a member of the "manager" security group.
- Earlier we created a user in
auth_user
called Julio Iglesias and a security group called manager in auth_group
which we defined in the Database Administration page. - We also create an entry in the
auth_membership
table for the user and the group. - Once the user has logged in, the grid object is rendered in the browser as shown below.
[ Previous ] [ Next ]