INTRODUCTION TO FLASK - Tourist Attractions

Step 21 is giving me problems, am I missing something?

from flask import Flask, render_template, request, redirect, url_for from locations import Locations from forms import AddLocationForm 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 request.method == "POST": [(name, action)] = request.form.items() 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", category=category, categories=categories, locations=locations, add_location=AddLocationForm()) @app.route("/add_location", methods=["POST"]) def add_location(): ## Validate and collect the form data add_form = AddLocationForm() if add_form.validate_on_submit(): visit.add(name, description, category) ## Redirect to locations route function return redirect(url_for("locations"), category="category", _external=True, _scheme='https') @app.route("/") def index(): ## Redirect to locations route function return redirect(url_for("locations"), category="recommended", _external=True, _scheme='https')

I’m not overly familiar with flask so I’ll not be able to help but please see How do I format code in my posts? to make your formatting clear for anyone else who tries to assist :slightly_smiling_face:. A link to the project would be a good idea too (what is step 21?). Here’s a general FAQ on how best to set up a question, cheers.

1 Like

I use exactly the same code. What is the error? Mine does not add a location. No errors, but my added location does not appear.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.