Python Forum
How To Display this Python Code in Web browser?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To Display this Python Code in Web browser?
#1
I have a sample code. how to display the output in web broswer?
For i in range(0, 11):
           print(i)
answer will be:-
0
1
2
3
4
5
6
7
8
9
10

how to display it in web browser, looking for code and solution.
Reply
#2
I think a clean way is with Flask and Jinja on client side,demo under.
Other ways as you may know so do not Python execute in in browser,as JavaScript dos.
There are several projects that compile Python to JS.
List of project that compile to JS.

Flak demo,so on server i can have a lazy evaluated lst,that get evaluated on client with Jinja
app.py:
from flask import Flask, render_template

app = Flask(__name__)
@app.route('/')
def num_list():
    lst = range(0, 11)
    return render_template("index.html", lst=lst)

if __name__ == "__main__":
    app.run(debug=True) 
index html.
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Page Title</title>
</head>
  <body>
    {% for item in lst %}
        <p> {{ item }} </p>
    {% endfor %}
  </body>
</html>
λ python app.py
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 334-187-997
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display <IPython.core.display.HTML object>? pythopen 3 45,704 May-06-2023, 08:14 AM
Last Post: pramod08728
  How can I display dictionary in a gui window in Python? C0D3R 2 1,661 Apr-07-2022, 07:33 PM
Last Post: C0D3R
Question Opening small size browser with python selenium not work, need help greenpine 0 1,587 Feb-07-2022, 11:36 AM
Last Post: greenpine
Information Unable to display joystick's value from Python onto display box MelfoyGray 2 2,173 Nov-11-2020, 02:23 AM
Last Post: MelfoyGray
  How to Display a QR code MattLumb 3 2,471 Jun-02-2020, 01:38 AM
Last Post: MattLumb
  python display with '\\' when prints with key-value in dictionary maiya 12 9,313 May-30-2020, 05:56 PM
Last Post: maiya
  NameError: name 'display' is not defined when running code on power bi beginner1 2 19,019 Jul-24-2019, 11:03 AM
Last Post: beginner1
  Escape sequences display in python Uchikago 1 2,377 Jun-27-2019, 03:25 PM
Last Post: Gribouillis
  Python code error on browser. adi.6194 3 5,180 Oct-27-2016, 03:20 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020