Banjo app
Lab setup
First, make sure you have completed the initial setup.
If you are part of a course
-
Open Terminal. Run the update command to make sure you have the latest code.
$ mwc update
-
Move to this lab's directory.
$ cd ~/Desktop/making_with_code/ny-csdf/unit1/project_banjo_app
-
Enter this lab's shell environment.
$ poetry shell
If you are working on your own
-
Move to your MWC directory.
$ cd ~/Desktop/making_with_code
-
Get a copy of this lab's materials.
git clone https://git.makingwithcode.org/mwc/project_banjo_app.git
Now it's your turn to create a Banjo app. Before you start programming, you need to design your app by considering a few key questions.
Teacher portal case study
Start by reading this case study of a much larger design process, for a different kind of software. However, the design questions which need to be answered are the same.
Example: Cookbook
💻
Now let's look at the design of an app you could create in Banjo. Run the server by
moving into the cookbook
directory, running banjo
, and opening
http://localhost:8000/api. Try out the app: you can import recipes by URL from
cooking sites like All Recipes, you can search for recipes, and you can add notes.
1. Who will use your app? (Who is your app's target user?) This is an app for people who like to cook, specifically me. I expect users to host this app on their own computer for their own use. The app will not support multiple users.
2. What need or problem will your app solve? How do you know this is really a need for your target user? How does the target user currently deal with the problem?
I have three main goals for this app:
- Collect recipes I like.
- Search for a recipe when I'm thinking about what to cook.
- Store notes about the recipe.
Honestly, I'm creating this app for myself, so I'm not worried about whether it meets other people's needs. The main alternative to this app is searching for recipes online, but I find online recipe websites unpleasant to use because they have so many ads and unnecessary text.
3. How will your app's design meet the need you have identified?
- To collect recipes, I will import them from recipe websites. I found a Python project called
scrape-schema-recipe which reads
metadata from recipes, so the hard work is done! (You can install new packages in your project using
poetry add project-name
.) - I will support search for recipes by name or by ingredient.
- I will also support attaching notes to a recipe.
4. How could your app possibly cause harm? (For example, could someone get hurt if data leaked or if someone used the app inappropriately?) What steps will you take to ensure that nobody is harmed by your app?
This app is unlikely to cause harm. Because the app is only intended for an individual user on their own computer, we don't have to worry about abuse from other users. There is no issue with violating the copyright of recipe websites--importing recipes is equivalent to saving a webpage. It is possible that recipes have been uploaded to recipe websites in violation of copyright.
Assignment
Now implement your design as a Banjo app.
💻
To get started, create a new directory for your project (the code below
uses project
, but you might want to choose a more descriptive name), create an app
directory
inside, and create models.py
and views.py
inside of app
:
$ mkdir project
$ cd project
$ mkdir app
$ touch app/models.py
$ touch app/views.py
Open your project in your editor:
$ code .
And then start the Banjo server. We use --debug
so that we'll get useful error messages
when something goes wrong.
$ banjo --debug
Open your project in your browser at http://localhost:8000.
Banjo will live-reload your app, so as you make changes to models.py
or views.py
,
the web page connects to the latest version of your code.
Develop your app step-by-step, making small changes and testing them out. It usually works better to work bottom-up for web apps, starting by creating your models and then creating your views, but it's up to you.