I don´t understand what do I have to do on step 2, it says:
Good job. Our web content doesn’t look like much, just a couple buttons that are part of a web form. In order to work on our template we’ll need to create some template variables and assign the application data to them. Currently our application data consists of:
-
category
: The URL string variable that defines the current category page. -
categories
: A dictionary with thecategory
string as the keys and display ready categories as the items. -
locations
: A list ofLocation()
objects as defined in locations.py . This is a list of only the locations associated with the string variablecategory
.
In app.py add 3 variables using keyword arguments:
- Create template variable
category
and assign it the app variablecategory
- Create template variable
categories
and assign it the app variablecategories
- Create template variable
locations
and assign it the app variablelocations
And this is the code:
from locations import Locations
app = Flask(__name__)
app.config['SECRET_KEY'] = 'SECRET_PROJECT'
visit = Locations()
categories = {"recommended": "Recommended", "tovisit": "Places To Go", "visited": "Visited!!!", }
UP_ACTION = "\u2197"
DEL_ACTION = "X"
@app.route("/<category>", methods=["GET", "POST"])
def locations(category):
locations = visit.get_list_by_category(category)
## Check the request for form data and process
if False:
[(name, action)] = [(None, None)]
if action == UP_ACTION:
visit.moveup(name)
elif action == DEL_ACTION:
visit.delete(name)
## Return the main template with variables
return render_template("locations.html")
@app.route("/add_location", methods=["POST"])
def add_location():
## Validate and collect the form data
if True:
name=None
description=None
category=None
visit.add(name, description, category)
## Redirect to locations route function
return ""
@app.route("/")
def index():
## Redirect to locations route function
return ""```