Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does it really works
#2
A little history Why is WSGI necessary,so Python community did write an all Python solution PEP 3333.
Today is all Python web-frame build on top this solution(WSGI),and CGI(the old way) is not used at all.
Full Stack Python Wrote:WSGI is by design a simple standard interface for running Python code.
As a web developer you won't need to know much more than this
Flask and Django are the two most know.

Staring with Flask can be smart as it has less overhead and feel like you are closer to HTML/CSS/JavaScript.
Here is simple setup i have posted before.
my_app
|-- app.py
  templates\
    |-- index.html
    |-- about.html
  static\
    css\
      |-- style.css
    js\
    img\
app.py:
from flask import Flask, render_template, jsonify, request
 
app = Flask(__name__)
@app.route('/')
def index():
   return render_template("index.html")
 
@app.route('/about',  methods=['GET'])
def about():
   return render_template("about.html") 

if __name__ == '__main__':
   app.run(debug=True)
index.html:
<!doctype html>
<html>
  <head>
     <meta charset="UTF-8">
    <title>Some title</title>
    <link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/style.css') }}" />
  </head>
  <body>
    <div id="start">
      <h1>Start page</h1>
      <ul>
        <li class="page_1"><a href="/about">About</a></li>
      </ul>
    </div>
  </body>
</html>
about.html:
<div class="foo">
  <h1>The About Page</h1>
  <a href="https://python-forum.io/">Python forum</a>
</div>
style.css:
body { 
  background: #67B26F;  
  background: -webkit-linear-gradient(to right, #4ca2cd, #67B26F);
  background: linear-gradient(to right, #4ca2cd, #67B26F);
  font-size: 100%;
  padding:0; 
  margin:0;		
}

html {
  height: 100%
}

#wrapper {
width: auto;
}
Now from command line in folder where app.py is.
Run python app.py.
Then it look like this,see that web-server is build for easy local development.
E:\all_flask\2019\my_app
λ 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)
See address copy that to browser http://127.0.0.1:5000/.
Then should show the page and with a link to about page.
Reply


Messages In This Thread
How does it really works - by Somnath - May-13-2019, 03:42 PM
RE: How does it really works - by snippsat - May-13-2019, 10:24 PM

Forum Jump:

User Panel Messages

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