JkAlcntr / ITE-306-MODULE-19-ALCANTARA

Web Framework using Python Flask

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ITE 306 Module 19 Alcantara

Web Framework using Python Flask

We wil require two package to setup your environment.

To Install Flask & virtualenv open CMD and type the following commands:

  1. virtualenv
pip install virtualenv

Once installed, new virtual environment is created in a folder.

mkdir newproj
cd newproj
virtualenv venv

To activate corresponding environment, on Windows, use the following

venv\scripts\activate
  1. Flask

We are now ready to install Flask in this environment.

pip install Flask

myflask1.py

Step 1: Test & Run

To start, open myflask1.py and do the following:

from flask import Flask
app = Flask(__name__)

@app.route('/hello/<name>')
def hello_name(name):
      return 'Hello %s!' % name

if __name__ == '__main__':
          app.run()

It should be like the following:

C:\Users\Desktop>python C:\Users\Desktop\myflask1.py

The Output would be:

* Serving Flask app 'myflask1'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit

Step 2. TRY

Now try this

Enter this URL http://127.0.0.1:5000/hello/<name>

replace <name> with your name.

Example:

http://127.0.0.1:5000/hello/John

Output would display like this:

Hello John!

Good job!👍

myflash2.py

Step 1. Download the pythontest folder or copy files located inside it.

Step 2. Repeat the procedure same as the above run the myflask2.py on cmd after that;

Step 3. Open login.html file in your selected browser

Step 4. Enter name

https://github.com/JkAlcntr/ITE-MODULE-19-ALCANTARA/blob/main/Capture.PNG

Step 5. Click Submit

Output will show:

Welcome John

About

Web Framework using Python Flask


Languages

Language:Python 66.5%Language:HTML 33.5%