Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does it really works
#1
Attention: This is by far the most silliest question you would have ever heard. But, I am asking this bcoz I am absolutely naive on Python and I am not getting this cleared from any where.

My Background: I know web development using HTML, CSS, Bootstarp etc. I am an absolute beginner to Python. So, my question is How does Python works?

For a web developer- he/she writes a HTML code and styles it with CSS in the editor and makes a webpage that will run on the internet.

But, I dont know how does it works here in Python. We install Python and then PyChamp then PIP etc. Print Hello world in the Pychmap and see that it gets printed on the terminal. Now, how o where will the codes run? will it be in a web browser or anything else. I am not clear. I am not clear what am I trying to do with writing codes on the PyChamp and seeing it working on the terminal.

Hope my question is clear to you all. Any advise or suggestion would be greatly appreciated. Because I am sure I am missing something very crucial here.
Reply
#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


Forum Jump:

User Panel Messages

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