A simple Flask application with routing and Jinja templates. Accompanying slides can be found here.
git clone https://github.com/hack4impact/flask-workshop.git
cd flask-workshop
If you do not have git installed on your computer, you can also download the .zip file.
Modifying your PATH environment variable
If you do not have pip already installed on your computer, follow this tutorial to install pip.
pip install virtualenv
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
python manage.py recreate_db
python manage.py add_fake_data
source venv/bin/activate
python run.py
Then navigate to http://localhost:5000/
on your preferred web browser.
deactivate
- Flask Workshop Slides
- Flask-Base is a simple Flask boilerplate app with SQLAlchemy, Redis, User Authentication, and more. Check out our documentation as well!
- Flask documentation
- Jinja documentation
- Flask extensions
- Play around with the templates.
- Try changing the text, color, etc. and see what happens!
- Add new routes.
- Add a new route
/noonoos
inviews.py
that will rendernewbies.html
. - Add a new route
/newbiesf19
inviews.py
that redirects to/newbies
.- Think about how these two might be different!
- Add a new route
- Create a new template and a new route.
- Create a new template
bootcamp.html
. Put any HTML you want there (feel free to copy pasteindex.html
!) - Create a new route
/bootcamp
inviews.py
.
- Create a new template
- Add a new column to the
Newbie
model.- Add a column called
fave_snack
innewbie.py
. This should be of typeString
.- Since you modified the database, you'll need to recreate the database. This can be done by running
python manage.py recreate_db
.
- Since you modified the database, you'll need to recreate the database. This can be done by running
- Add a column called
- Now that you've added a new column to
Newbies
, you'll need to change the form so thatfave_snack
can be inputed as well.- Add a
StringField
calledfave_snack
toAddNewbieForm
informs.py
.
- Add a
- Next, you need to update the frontend for the form so that a user can actually input this new information.
- In
add_newbie.html
, render the new field you just added toAddNewbieForm
.
- In
- This additional information needs to be added to the database once a user submits the form.
- Edit
add_newbies()
inviews.py
to also include the newfave_snack
data.
- Edit
- Display this new information.
- Edit
newbies.html
to also display every newbie'sfave_snack
as well.
- Edit
Learn about one-to-many and many-to-many relationships in the database-workshop branch by following this guide. To view the example code:
git pull
git checkout database-workshop