From 5f5ca9fda319fb16efbc50dd6c38381378a266af Mon Sep 17 00:00:00 2001 From: Neslihan Date: Sun, 28 Feb 2021 23:03:51 +0300 Subject: [PATCH] Add template for check text and result --- app/forms.py | 5 +++++ app/routes.py | 17 +++++++++++++---- app/templates/index.html | 15 +++++++++++++++ app/templates/result.html | 5 +++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 app/templates/index.html create mode 100644 app/templates/result.html diff --git a/app/forms.py b/app/forms.py index 6f3d5ee..eabc11c 100644 --- a/app/forms.py +++ b/app/forms.py @@ -4,6 +4,11 @@ from wtforms.validators import ValidationError, DataRequired, Email, EqualTo from app.models import User +class CheckForm(FlaskForm): + text = StringField('Text to be checked', validators=[DataRequired()]) + submit = SubmitField('Check') + + class LoginForm(FlaskForm): username = StringField('Username', validators=[DataRequired()]) password = PasswordField('Password', validators=[DataRequired()]) diff --git a/app/routes.py b/app/routes.py index d1af06f..15413ca 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,16 +1,25 @@ from app import app from app import db -from app.forms import LoginForm, RegistrationForm +from app.forms import LoginForm, RegistrationForm, CheckForm from app.models import User -from flask import render_template, flash, redirect, url_for +from flask import render_template, flash, redirect, url_for, request from flask_login import current_user, login_user, logout_user from flask_login import login_required @app.route('/') -@app.route('/index') +@app.route('/index', methods=['GET', 'POST']) def index(): - return "Hello, World!" + form = CheckForm() + if request.method == 'POST': + text = request.form['text'] + return render_template('result.html', title='Result', text=text) + else: + if form.validate_on_submit(): + flash('Check requested for text {}'.format( + form.text.data)) + return redirect(url_for('index')) + return render_template('index.html', title='Check', form=form) @app.route('/register', methods=['GET', 'POST']) diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..6f8b1cb --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} + +{% block content %} +
+
+
+
+ + +
+
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/app/templates/result.html b/app/templates/result.html new file mode 100644 index 0000000..4beeb53 --- /dev/null +++ b/app/templates/result.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block content %} + {{ text }} +{% endblock %} \ No newline at end of file