Update main.py
parent
85faafeca5
commit
85d4177c3d
34
main.py
34
main.py
|
@ -1,7 +1,35 @@
|
|||
from flask import Flask
|
||||
from flask import Flask, make_response, render_template, request, redirect, url_for
|
||||
from markupsafe import escape
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return "This is an example app"
|
||||
@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('/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()
|
||||
|
|
Loading…
Reference in New Issue