web.py detailed steps for using templates

Source: Internet
Author: User

The interpretation of the Python Network Programming Learning Note (WEBPY): Framework (http://www.cnblogs.com/xiaowuyi/archive/2012/11/15/2771099.html#3006443).

Netizen @etfengyun recently raised doubt, webpy0.33 on the use of template error occurred. As I did not reproduce the error according to @etfengyun, so it is not good to judge the cause of the error, the concrete use of the template to explain the steps in detail.

1, Environment: python2.7.x+webpy0.33 (: http://webpy.org/static/web.py-0.33.tar.gz)

2. Create Test folder, The webpy0.33 extracted Web folder is placed under test, and the establishment of testwebpy.py file and the creation of Templates folder, under the Templates folder, the creation of index.html file, the file content is:

$def with  (name) $if  name:    <em>hello</em> to $name. $ Else :     <em>hello</em>, world!

3, the testwebpy.py code:

##@ Xiao Wu Yi Http://www.cnblogs.com/xiaowuyiImportWebrender= Web.template.render ('templates/') URLs= (    '/','Index')classIndex:defGET (self): name='Bob'        returnRender.index (name)#return "Hello, world!"if __name__=="__main__": App=web.application (URLs, Globals ()) App.run ()

Operating effect:

Code Listing 2:

##@ Xiao Wu Yi Http://www.cnblogs.com/xiaowuyiImportWeb Render= Web.template.render ('templates/') URLs= (     '/(.*)','Index' ) classIndex:defGET (self,name): I=web.input (name=None)returnRender.index (name)#return "Hello, world!"if __name__=="__main__": App=web.application (URLs, Globals ()) App.run ()

Operating effect:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.