For this exercise, you'll be writing the back end code to support a fully built front end. You will also practice creating a global search feature that allows the user to search for pokemon and teams. The application is also live at https://intense-dusk-62733.herokuapp.com/ if you would like to see how it works.
- Flask
- Jinja
- AJAX
- API calls
- Command Line
- Git
- GitHub
For you
/templates
- Contains all of the HTML templates in your application. There are two:index.html
is for the homepage located atlocalhost:5000
, anddetail.html
is for an individual pokemon's page located atlocalhost:5000/:id
where:id
is the Pokemon's ID number. For example,localhost:5000/1
should be the page for Bulbasaur./static/css
- Contains each of the CSS files for each of the HTML files in/templates
. Soindex.css
is forindex.html
anddetail.css
is fordetail.html
/static/js
- Contains each of the JavaScript files for each of the HTML files intemplates
. Soindex.js
is forindex.html
anddetail.js
is fordetail.html
. This folder also containsjquery.min.js
for jQuery. It's already installed in each of your HTML files in/templates
and you can see how it's installed there.
Do not touch
README.md
- The instructions you're reading right now.setup.sh
- The file that will set your application up for you. See the "Setup" instructions below.requirements.txt
- A file that stores all of your Python dependencies (e.g. Flask) so when you runpip install -r requirements.txt
, you'll download all the dependencies you need. For more information, see "How setup.sh works"app.py
- The Python file that starts your web application. This file is written using the Flask framework, and it's been commented with some information to help you understand how it works. For this exercise, you should not change anything in this file, but feel free to explore. We will be working on the server side code in the next exercise..gitignore
- A file that tellsgit
which files to ignore when you use version control./data
- A folder that contains all of the Pokemon data for your application. In future exercises, this will be replaced with other ways of storing data./venv
- A folder that contains all of your virtual environment files and downloaded dependencies frompip
. For more information, see "How setup.sh works"/__pycache__
- You'll probably have this folder generated. It is something created by Python 3 when you run it, and you can safely ignore it.
These instructions are a simplified version of the Flask installation instructions and quickstart. If you have any questions, feel free to reach out to me.
- Clone this repository using
git clone
andcd
from your command line into the repository folder. - Make sure you have Python 3 installed. You can check this by seeing if the command
python3
works in your command line. If you successfully runpython3
, you can exit the interpreter by typingquit()
then hitting Enter. If you don't have Python 3 installed, follow these instructions. - From the root of the repository, run the following command:
sh setup.sh
. This is a file I've written to automate the initial setup of this application. It will start your app automatically, and you can go tolocalhost:5000
in a web browser to view it. If you want detailed instructions on how this file works, go to "How setup.sh works" below. - Whenever you're about to work on your application, make sure to run
. venv/bin/activate
first to start your virtual environment, then you can runflask run
from the root of your repository to start your application.
- To stop your server it's running in the command line, hit
Control + C
to stop the server. - If you change your HTML files, you'll have to restart the server to see changes.
- Python 3 comes with venv, a "virtual environment" to manage packages like
Flask
that you'll need to run your application. When you first clone this repository, runpython3 -m venv venv
from the root of the repository to create a virtual environment for your application. This will create a few folders and files related to venv, in avenv
folder. - Once you've set up a virtual environment, whenever you're about to work on your app, make sure to run
. venv/bin/activate
from the root of the repository. You should then see(venv)
prefixed in your command line to show that you're using the virtual environment. After you do this, you should be able to download packages and run your application. - Once you are using the virtual environment, make sure you install all the dependencies for this application by running
pip install -r requirements.txt
(if you're using Python 3, you might need to usepip3
instead ofpip
. You only need to do this once and don't need to again when you want to run your application. - Once you have
Flask
properly installed, make sure you set your environment variables so Flask knows what file to start with. In this repository, the app starts with the fileapp.py
. If you renameapp.py
or want to use a different file as the entrypoint, you'll have to runexport FLASK_APP={FILENAME}
and replace{FILENAME}
with the correct filename to make sure the app runs. - Once you have everything setup, you should be able to run
flask run
and your server should start listening. Go to a browser atlocalhost:5000
and you should see your app running.
You'll be focusing on the front end of the application. Future exercises will be built on top of the knowledge you gain from this exercise. You'll be focusing on the front end of the application. Future exercises will be built on top of the knowledge you gain from this exercise. In addition to the requirements below, you can see the full solution of this application running at https://sleepy-earth-06238.herokuapp.com/.
- API (
localhost:5000/api
) - You need to fill out all the of API endpoints that return "Fix me!" in/api/pokemon.py
and/api/teams.py
:
- The front end of the application is complete: use it to guide your decisions building the APIs
- You should be completing these endpoints using the REST pattern
- The pokemon API allows you to get a single pokemon record or lists all the pokemon in the database
- The pokemon API has an additional requirement on getting all pokemon: it can also filter results using a search paramater
- The teams API allows for all basic REST: get all teams, get one team, create a team, delete a team, update an entire team, update a team partially
- Search (
localhost:5000/search
) - You will need to write the back end for this route (app.py
) and use Jinja to render the results (/templates/search.html
):
- In the back end, requirements are laid out in comments. There are additional requirements if you finish early.
- Your search page should show the number of results, the original query, and a ranked list of all the results.
- Each search result should have a working link to its detail page, specify what type of item it is (pokemon or team), and a description.
- Both the home page at
localhost:5000
and the search page should have a search bar that takes the user search results page that fires on submission. - When rendering the results, do NOT use JavaScript or AJAX.