How to make web element generation simpler in python-Python tutorial

Source: Internet
Author: User
Web is not simple, especially when you need some web effects, such as displaying a rounded rectangle or prompt box, you may think it is very simple. let's analyze it: 1. reference css. This is probably the most common practice. it defines a specific style for some specific elements. To use it, you need
Add Label.
2. introduce js. Many special effects can also be processed using javascript, such as dynamic display effects or element encapsulation. Use
You need to add the script tag to the HTML page, and add some javascript code when necessary.
3. HTML elements. You need to set some special attributes, such as class = A certain attribute. This is relatively simple.

Therefore, from the analysis above, we can see that adding a nice web element may be modified in many places. Therefore, I
I am thinking about how to simplify this process. The trouble is how to deal with these resources and how to make these resources
What about the combination of HTML? The final solution I came up with was code assembly.

For css, javascript links, and code, they can be assembled into a piece of text in the order of calling, and then insertedBefore element
. Then, the html code is output directly in the template. For css, the javascript link can check whether the link is repeated.

So how to define the web element class and how to process it in the template?

A web element class is defined as follows:

Class Snippet (object ):
Css =''
Csslink =''
Jslink =''
Html =''
Js =''

Def render (self ):

Def _ str _ (self ):
Return self. render ()

If it is defined as a class property, it will be output to the HTML header, and the result of render () will be displayed in the place where the class is called in the template. First take a look at the template
For example:


HTML Helper

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: 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.