├── Miguel Grinberg - Flask Web Development_ Developing Web Applications with Python-O'Reilly Media (2014).pdf ├── README.md ├── WTForms standard HTML fields.png ├── WTForms validators.png ├── flaskapplication.py ├── history.txt ├── randomStringGenerator.py └── templates ├── 404.html ├── base.html ├── index.html └── user.html /Miguel Grinberg - Flask Web Development_ Developing Web Applications with Python-O'Reilly Media (2014).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naimul011/FlaskWebDevelopment/9142a0d3c35e1ac6227e269a10e3001d8a50a387/Miguel Grinberg - Flask Web Development_ Developing Web Applications with Python-O'Reilly Media (2014).pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FlaskWebDevelopment 2 | ## https://www.youtube.com/playlist?list=PL5WWFMzXof5hA8cLzEoim7BEkHcmddbOK 3 | Flask NameForm 4 | This is a simple Flask web application that displays a form where a user can input their name, and upon submission, their name is displayed on the page. 5 | 6 | ## Requirements 7 | * Flask (version 1.0 or higher) 8 | * Flask-Bootstrap (version 3.3 or higher) 9 | * Flask-WTF (version 0.14 or higher) 10 | * WTForms (version 2.1 or higher) 11 | ## Installation 12 | Clone or download the repository to your local machine. 13 | Install the required packages by running pip install -r requirements.txt. 14 | Run the application by executing python app.py. 15 | ## Usage 16 | Once the application is running, open a web browser and navigate to http://localhost:5000. You will see a form where you can input your name. Upon submission, your name will be displayed on the page. 17 | 18 | You can also visit http://localhost:5000/user/ to see a personalized page with your name displayed. 19 | 20 | If you encounter a 404 error, a custom error page will be displayed. 21 | -------------------------------------------------------------------------------- /WTForms standard HTML fields.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naimul011/FlaskWebDevelopment/9142a0d3c35e1ac6227e269a10e3001d8a50a387/WTForms standard HTML fields.png -------------------------------------------------------------------------------- /WTForms validators.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naimul011/FlaskWebDevelopment/9142a0d3c35e1ac6227e269a10e3001d8a50a387/WTForms validators.png -------------------------------------------------------------------------------- /flaskapplication.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, session, redirect, url_for, flash 2 | from flask_bootstrap import Bootstrap 3 | from flask_wtf import Form 4 | from wtforms import StringField, SubmitField 5 | from wtforms.validators import Required 6 | 7 | class NameForm(Form): 8 | name = StringField('What is your name?', validators=[Required()]) 9 | submit = SubmitField('Submit') 10 | 11 | app = Flask(__name__) 12 | bootstrap = Bootstrap(app) 13 | app.config['SECRET_KEY'] = '7cwtzhl0tkg9obj9' 14 | 15 | 16 | 17 | @app.route('/', methods=['GET', 'POST']) 18 | @app.route('/index', methods=['GET', 'POST']) 19 | def index(): 20 | form = NameForm() 21 | if form.validate_on_submit(): 22 | old_name = session.get('name') 23 | if old_name is not None and old_name != form.name.data: 24 | flash('Looks like you have changed your name!') 25 | session['name'] = form.name.data 26 | form.name.data = '' 27 | return redirect(url_for('index')) 28 | return render_template('index.html', 29 | form = form, name = session.get('name')) 30 | 31 | @app.route('/user/') 32 | def user(name): 33 | return render_template('user.html', name=name) 34 | 35 | @app.errorhandler(404) 36 | def page_not_found(e): 37 | return render_template('404.html'), 404 38 | 39 | if __name__ == '__main__': 40 | app.run(debug=True) 41 | -------------------------------------------------------------------------------- /history.txt: -------------------------------------------------------------------------------- 1 | 992 git push -u origin master 2 | 993 history | tail > history.txt 3 | 994 git commit -m "Installing Flask-WTF extension" 4 | 995 cat history.txt 5 | 996 git add history.txt 6 | 997 git commit -m "Installing Flask-WTF extension" 7 | 998 git push -u origin master 8 | 999 gedit randomStringGenerator.py 9 | 1000 python3 randomStringGenerator.py 16 10 | 1001 history | tail > history.txt 11 | -------------------------------------------------------------------------------- /randomStringGenerator.py: -------------------------------------------------------------------------------- 1 | import random 2 | import string 3 | import sys 4 | 5 | size = int(sys.argv[1]) 6 | 7 | def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits): 8 | return ''.join(random.choice(chars) for _ in range(size)) 9 | 10 | 11 | print(random_string_generator(size=size)) 12 | -------------------------------------------------------------------------------- /templates/404.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block title %}Flasky - Page Not Found{% endblock %} 3 | 4 | {% block page_content %} 5 | 8 | {% endblock %} 9 | -------------------------------------------------------------------------------- /templates/base.html: -------------------------------------------------------------------------------- 1 | {% extends "bootstrap/base.html" %} 2 | 3 | {% block title %}Flasky{% endblock %} 4 | 5 | {% block navbar %} 6 | 25 | {% endblock %} 26 | 27 | {% block content %} 28 |
29 | {% for message in get_flashed_messages() %} 30 |
31 | 32 | {{ message }} 33 |
34 | {% endfor %} 35 | {% block page_content %}{% endblock %} 36 |
37 | {% endblock %} 38 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% import "bootstrap/wtf.html" as wtf %} 3 | 4 | {% block title %}Flasky{% endblock %} 5 | 6 | {% block page_content %} 7 | 8 | 11 | {{ wtf.quick_form(form) }} 12 | 13 | {% endblock %} 14 | -------------------------------------------------------------------------------- /templates/user.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block title %}Flasky{% endblock %} 3 | 4 | {% block page_content %} 5 | 8 | {% endblock %} 9 | --------------------------------------------------------------------------------