Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use python to program webpy framework template def with

Shulou Source: shulou.com Published: 2022-06-02 13:21:59 10月26日 Update

This article introduces the knowledge of "how to use python to program webpy framework template def with". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

One: the understanding of the template

Template is the result of fixing and standardizing the structural law of a thing.

For example: the composition of the web page needs to be html,head,body, you only need to write according to its rules, how it is implemented, you need to know other knowledge.

Web.py: pages are uniformly mapped through html files and background classes, and the web framework provides a complete mechanism for html files to obtain parameters in classes.

Second: simple template

1. Create a new file html in your directory and create an index.html file in this folder

What is in the index.html:

Web simple template Hello, I'm web simple template

two。 Get the html folder I just created

Render = web.template.render ('html/') # the framework goes to the html directory to find all the html files.

3. Operate according to the name of the specific file

Render.index () # index represents the index.html I created

4. Example

Running result:

The default port is 8080. You can also change the port.

Python project name. py port number

Three: def with

1. Transfer parameters

Name=' Zhang San'

Render.index (name) # index indicates that the index.html,name I created represents how many parameter values are in the file. {parameters can be multiple}

two。 Accept parameters

Pay attention to the space problem:

Running result:

Four: pay attention

1. Port number problem

2. The problem of spaces in index.html

3. Multiple program startup problems, you may need to end multiple processes in the execution of the program

This is the end of "how to use python to program webpy framework template def with". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Files templates parameters frameworks questions content multiple knowledge programming slogans folders more directories programs ports results run practical learned next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei Docker MariaDB Redmi