Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python x Html5
#1
What's the best way to output code (html) and file (html) through python?
Reply
#2
Can do it trough webbrowser module.
It's just for display and not flexible as a web-framework.

Example a light weight Flask
Look at this post,for a simple setup.
render_template("index.html") get renderd in browser bye Jinja.

This is the simplest way,CGI is dead and using WSGI directly is a lot more work.
WSGI was very important for Python,and all Python web-framework is now build on top of it.
Reply
#3
(Sep-29-2019, 02:46 PM)snippsat Wrote: Can do it trough webbrowser module.
It's just for display and not flexible as a web-framework.

Example a light weight Flask
Look at this post,for a simple setup.
render_template("index.html") get renderd in browser bye Jinja.

This is the simplest way,CGI is dead and using WSGI directly is a lot more work.
WSGI was very important for Python,and all Python web-framework is now build on top of it.

Do you know the way of stones to develop an html5 interpreter?
Reply
#4
(Sep-30-2019, 07:07 PM)JohnnyCoffee Wrote: Do you know the way of stones to develop an html5 interpreter?
HTML is text markup language,there is no interpreter or compiler required in HTML.
Markup language is used to describe the visual appearance of a document to be displayed.

Browsers who deal with HTML do contain something similar to a interpreter(called parser).
Parser will identify various tags and display them accordingly - it depends on the way tags are rendered in browser.
One of the component in web browser is called rendering engine that performs this task.

Jinja2 is a template engine that generate HTML.
This mean that we can have Python code like eg a list and can make a loop in HTML that will render vaild HTML.
Server:
from flask import Flask, render_template 

app = Flask(__name__)
@app.route('/')
def index():
    list_example = ['Python', 'HTML', 'CSS']
    return render_template('index.html', list_example=list_example)
 
if __name__ == '__main__':
    app.run(debug=True)
Client in Browser:
<!DOCTYPE html>
<html>
<head>
  <title>Conditions</title>
</head>
<body>
<ul>
  {% for name in list_example %}
    <li>{{ name }}</li>
  {% endfor %}
</ul> 
</body>
</html>
Reply
#5
(Sep-30-2019, 08:39 PM)snippsat Wrote:
(Sep-30-2019, 07:07 PM)JohnnyCoffee Wrote: Do you know the way of stones to develop an html5 interpreter?
HTML is text markup language,there is no interpreter or compiler required in HTML. Markup language is used to describe the visual appearance of a document to be displayed. Browsers who deal with HTML do contain something similar to a interpreter(called parser). Parser will identify various tags and display them accordingly - it depends on the way tags are rendered in browser. One of the component in web browser is called rendering engine that performs this task. Jinja2 is a template engine that generate HTML. This mean that we can have Python code like eg a list and can make a loop in HTML that will render vaild HTML. Server:
from flask import Flask, render_template app = Flask(__name__) @app.route('/') def index(): list_example = ['Python', 'HTML', 'CSS'] return render_template('index.html', list_example=list_example) if __name__ == '__main__': app.run(debug=True)
Client in Browser:
<!DOCTYPE html> <html> <head> <title>Conditions</title> </head> <body> <ul> {% for name in list_example %} <li>{{ name }}</li> {% endfor %} </ul> </body> </html>

Thanks for the answers
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  BeautifulSoup : how to have a html5 attribut searched for in a regular expression ? arbiel 2 2,578 May-09-2020, 03:05 PM
Last Post: arbiel

Forum Jump:

User Panel Messages

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