-1

It is necessary to integrate the html code in python so that it displays on output.

I searched all over the Internet, downloaded many different libraries, but they only do html code through python, and I needed it to be displayed on the screen.

Sample program:

#Could it look something like this?

import somelibrary

code = '''<!DOCTYPE html">
<html>
 <head>
  <title>sometitle</title>
 </head>
 <body>
  <h1>name</h1>
  <p>hello</p>
 </body>
</html>'''

somelibrary.show(code)

What should be the output

If you know how to do this, or at least something like that, libraries that can help, please let me know.

Let's clarify the situation. I am making a game on Ren'py(link), and to simplify the work (I need to do something like a phone), I want to use HTML (CSS and JS). So I asked if I could somehow do what I want. I do not make my website.

Stop harming Monica
  • 12,141
  • 1
  • 36
  • 56
MrTorex
  • 1
  • 1
  • 6
  • You should check out `PyQt5`'s `QWebEngineView`. – DjaouadNM Sep 14 '19 at 10:23
  • Just use any Python HTTP and respond with your HTML and look at it in your browser. – Sebastian Speitel Sep 14 '19 at 10:24
  • Let's clarify the situation. I am making a game on Ren'py([link](https://www.renpy.org/)), and to simplify the work (I need to do something like a phone), I want to use HTML (CSS and JS). So I asked if I could somehow do what I want. I do not make my website. – MrTorex Sep 14 '19 at 16:34
  • 1
    Possible duplicate of [Python: How Can I Render HTML Code And Show The Result To The User?](https://stackoverflow.com/questions/29908340/python-how-can-i-render-html-code-and-show-the-result-to-the-user) – Stop harming Monica Sep 14 '19 at 16:55

4 Answers4

1

What you are looking for is a template engine for python, that can dynamically generate html pages, and a server-side library that will help you send this html files to the client. for example, jinga (https://jinja.palletsprojects.com/en/2.10.x/) as template engine, and django as server-side library (as shina pointed out)

DrunkTolstoy
  • 36
  • 2
  • 6
0

You may have to checkout frameworks such as Flask (https://palletsprojects.com/p/flask/) or Django (https://www.djangoproject.com/start/), they provide a neat way of doing this.

0

If you are using django then use the djongo template viewer in order to add html to your code

0

You can create a file, say test.html, and store the HTML content there. Then open that file in your browser using below:

import webbrowser

# Open URL in a new tab, if a browser window is already open.
webbrowser.open('test.html')

# Open URL in new window, raising the window if possible.
webbrowser.open_new('test.html')

Note that webbrowser is not a core module therefore you'll have to install it first. Refer the documentation for more details.

Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133