exam_lasko/main.py

40 lines
1.1 KiB
Python

from flask import Flask, make_response, render_template, request, redirect, url_for
from markupsafe import escape
app = Flask(__name__)
@app.route('/')
@app.route('/<username>')
def index(username = None):
return render_template("index.html", name = username)
@app.route('/contact')
def contact():
return "<h3>Book your first consultation:</h3> <p>Epasts: example@example.com</p>"
@app.route('/')
@app.route('/<mikrobiologija>')
def first_page():
return render_template("first_page.html")
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
return redirect(url_for('index', username=escape(username)))
return render_template("form.html")
import unittest
class TestStringMethods(unittest.TestCase):
def test_upper(self):
client = app.test_client()
response = client.post("/login", data = {'username': "Test"})
response = client.get(response.location)
self.assertEqual(response.status_code, 200)
self.assertIn("Test", response.text)
if __name__ == '__main__':
unittest.main()