Flask - Textarea Login

Flask References:



Screens:

/b

Notes:


Code:

name = "Professor Nicholas Duchon - 030"
# from flask035 import *

# file: flask021.py
# date: Jun 5, 2020
# purpose: basic flask file with 3 pages
#   includes name and time stamps
#   make header prettier with a table

# time:
import time
def curtime () :
  return time.asctime(time.localtime(time.time()))

def pageEnd () :
  return "<hr>Time: " + curtime () + "</body></html>"

def textPage ():
    st  = ""
    # st += "<h1>in text page</h1>"
    st += """
    Flask 035
    <form action=regextest method=post>
        <label>regx Pattern:</label>
        <input type=text name=un>
        <p>
        <textarea id=textid name=textname rows=5 cols=30>
type your search text here.
        </textarea>
        <p>
        <input type=submit name=submit>
     </form>

    """
    return st

# File: flask010.py
from flask import Flask
app = Flask (__name__)

def pageStart (v, c) :
  sr = ""
  sr += """
    \n<html>
    \n<head>
    \n<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    \n<title>""" + name + ":" + v + """</title>
    \n</head>
    \n<body>
  """
  sr += "\n<table border=5 cellpadding=10 width=400"
  sr += " bgcolor=" + c
  sr += ">\n<tr><td>"
  sr += "\nPage: " + v
  sr += "\n<h2>" + name + "</h2>"
  sr += """
  \n<ul>
  \n<li><a href=/>link to /</a>
  \n<li><a href=a>link to a</a>
  \n<li><a href=b>link to b</a>
  \n</ul>
  \n</td></tr>
  \n</table>
  \n<hr>
  """
  return sr

@app.route ("/")
def reply () :
  str  = pageStart ("/", "yellow")
  str += "\n<h1>This is a simple web page - 001</h1>"
  str += "\n<h3>more stuff</h3>"
  str += pageEnd ()
  return str

@app.route ("/a")
def replyA ():
  str  = pageStart ('a', "#ffcc33")
  str += pageEnd ()
  return str
   
@app.route ("/b")
def replyB ():
  str  = pageStart ('b', 'pink')
  # str += "\n<P>regx example"
  str += textPage()
  str += pageEnd()
  return str

@app.route ("/regextest", methods=['GET', 'POST'])
def rep ():
  str  = pageStart ('b', '#99ff99')
  # str += "\n<P>regx example"
  str += textPage()
  str += pageEnd()
  return str
 
# see: https://flask.palletsprojects.com/en/1.1.x/api/
if __name__ == "__main__":
  app.run (host="0.0.0.0", port=8080)


Port

If you get a "OSError: [Errno 48] Address already in use" kind of error, (on port 8080) try:

(end)