Bottom Page

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.
Quote
#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)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Escape sequences display in python Uchikago 1 143 Jun-27-2019, 03:25 PM
Last Post: Gribouillis
  Can someone please help me convert this simple C ROT cipher code to Python code? boohoo9 5 206 Jun-14-2019, 03:02 PM
Last Post: DeaD_EyE
  If Python 2.x source code and applies a transform it into valid Python 3.x code. vivekm 1 145 May-20-2019, 05:12 PM
Last Post: Larz60+
  I cannot display object lists Karaca 2 149 May-07-2019, 08:29 AM
Last Post: Karaca
  Display Globar Variable N0m1t 1 200 Mar-19-2019, 10:29 PM
Last Post: metulburr
  display the contents of a sqlite3 database according to the dates atlass218 4 249 Mar-03-2019, 06:43 AM
Last Post: atlass218
  How to display what I write on sublime text editor on the CMD el_bueno 5 323 Feb-04-2019, 02:00 PM
Last Post: buran
  Full Screen Display daven2411 1 400 Oct-24-2018, 04:24 PM
Last Post: Larz60+
  How to display <IPython.core.display.HTML object>? pythopen 2 7,010 Oct-17-2018, 06:22 PM
Last Post: pythopen
  Convert C code to Python code lostMarbles 6 5,675 Sep-19-2018, 06:23 AM
Last Post: pcsailor

Forum Jump:


Users browsing this thread: 1 Guest(s)