Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write a web page using pure Python

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use pure Python to write a web page, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

When I was shopping on Github, I found a very cool artifact called remi, which has received 2300 likes so far.

There are not many star, but this library is one of the top ten star libraries selected in 2018. It claims to be an independent GUI library, and the most amazing thing is that this library is less than 100K. Isn't it amazing? let's experience and take a look at the features:

Different from other GUI libraries? Both Kivy,PyQT and PyGObject require native code for the host operating system, which means installing or compiling large dependencies. Remi only needs a Web browser to display your GUI.

Do I need to understand HTML? No, you just need to use Python for coding.

Is it open source? That's for sure! Remi is released under the Apache license. Open source, free!

Do I need some kind of web server? No, bring your own network server.

1. Installation

How to install it? because it is a Python library, you can use pip directly.

Pip install remi

If there is no network, or if the server is not connected to the external network, it can be installed offline. Download this package and install it with install

Python setup.py install

2. Quick experienc

Let's take a quick look at this simple Hello world page.

This contains two elements:

Text Hello world

A button for Press me

Clicking this button will also change the text content of Hello world, and it will become Button pressed.

The simple effect above actually takes only 20 lines of Python code, all native Python code, without a single line of HTML.

Let's take a look at the source code:

The structure of the whole code is still clear:

First declare a MyApp class that inherits the functions of the parent framework App and can be thought of as a web canvas

Then there are three functions in this canvas:

Init mainly does the initialization of classes.

Main mainly designs the canvas layout, including a text and a button.

On_button_pressed is mainly the corresponding control. Click on the trigger function.

Finally, start starts the class, which generates a local link to the site.

3. More complex web page elements

After reading the above design, you will feel that it is very similar to the famous tk library in Python, it is only an appetizer, and this remi can also provide more complex gui interface elements.

Thank you for reading this article carefully. I hope the article "how to use pure Python to write a web page" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report