Python Flask Primer In the Pycharm Professional Environment. Cookies!
We go over Flask, Pycharm Professional, setting up and handling of cookies and sessions in this primer.
Flask is a popular simple and easy to learn framework for building interactive websites to handle forms, logins and pretty much anything you might use on the internet.
- Used heavily by companies such as Samsung, Netflix, Trivago, and Reddit - 1000's of jobs list Flask as part of the requiem required. It is used and popular!
Let's get started.
Pycharm has native support for Flask. Starting a new project is this easy:
A small template will be built for you, and it is automatically setup to serve on Port 5000:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world(): # put application's code here
return 'Hello World!'
if __name__ == '__main__':
app.run()
A basic explanation:
@app.route('/')
Is a simple decorator that if one accesses the main page in this case:
http://127.0.0.1:5000/
It will serve the content 'Hello World!'
- It should be noted that Pycharm Professional really 'takes over' the handling of the port. Even with:
testing = False
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True)
It was still found to serve from port 5000, ignoring the app.run section of the code. We are required to run it in a separate terminal, even the Pycharm guide did not work:
flask run -h localhost -p 8080
Generating html requests.
Pycharm Professional is powerful! You can easily generate a html request by clicking on the world icon as in:
Another entire will be created with a GET html set:
Each time you run it - it will have a time stamped reference of what each page looked like. It lets you modify the code and see the differential outputs:
..to be continued