I want to know how to connect HTml with Python.

Asked 2 years ago, Updated 2 years ago, 18 views

These days, I'm trying to produce a program that works on kiosks like an unmanned system. The operating system is Windows and the language is Python, but if you use Python Gui, it doesn't look so good, so I'm going to make it by connecting it with a db server with HTml and css. Problem is...

There is a wx.html2 module among Python wxpython modules, but there is no problem when making one or two pages of the program There is a limit to mixing numerous page buttons and links, especially Python " comments with html code and JavaScript, so onclick=location.href doesn't work;; there are many restrictions, so I wonder how to link html documents to Python (backend)...

It's how long and flask works. What kind of module is this? I don't know how to use it The only thing I found was a module called htmlPy https://htmlpy.readthedocs.io/en/master/. There are so few tutorials

Please let me know if there are two ways

Example 1
import html ,css, js
htmlcod= """
<DOCTYPE html>
<head>
<style>
a.button{color:red; ......}
b.button{color:blue; ...}
...
<body>
<button type=button class=a ..... onclick="location.href='{page}'"></button>
...
</bdoy>
</html>
""".format(page=python)

python="Link Here"
Like this

(2) How to make html independently in a folder one by one and link it with Python Make page.html, page2.html in the folder and link these to Python (MVC pattern like Django?)

Either of them is fine Let me know if you can ㅜ<

python

2022-09-22 20:04

1 Answers

This is the contents of url below. Please refer to it. https://www.quora.com/How-do-I-run-Python-script-from-an-HTML-button

## In your HTML file:

<div>Relay 1:
  <form action= '{% url my_view_name%}' method="POST">
      <input type="submit" value="Toggle" id="toggle1" />
  </form>
</div>


## ## in urls.py
url(r'whatever^$', 'core.views.my_view',name='my_view_name'),


## ## In views.py:
def my_view(request):
    if request.method == 'POST':
        import set_gpio
        #Do your stuff ,calling whatever you want from set_gpio.py

    return #Something, normally a HTTPResponse, using django
Source Stack over flow


2022-09-22 20:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.