Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Create Page | FrontEnd Design
Flask Intensive Course: Web Development with Python

bookCreate Page

We have the option to move the form for creating a new recipe to a separate page. In doing so, we'll leave a convenient button for creating a new recipe on the recipe.html file.

To get started, let's create a fresh file named new-recipe.html. You'll find that it's going to look quite similar to what we had in recipes.html. So, go ahead and copy that piece of code and transfer it to the new file from the very beginning.

The file's name in the example below doesn't correspond to the file's name in our project.

new_recipe.html

new_recipe.html

copy

Now we need to create a route first to actually render this template.

# main.py

@app.route("/recipes/new/", methods=["GET", "POST"])
def new_recipe():
    if request.method == "POST":
        recipe_title = request.form["title"]
        recipe_description = request.form["description"]
        new_recipe = Recipe(title=recipe_title, 
    description=recipe_description, author="Joey")
        db.session.add(new_recipe)
        db.session.commit()
        return redirect("/recipes/")
    else:
        return render_template("new_recipe.html")

Now let's add a button to the recipe.html template for 'New recipe'.

<h1>All recipes</h1>
<a class="btn btn-success float-right" href="/recipe/new/">New recipe</a>

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 7

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Awesome!

Completion rate improved to 3.85

bookCreate Page

Glissez pour afficher le menu

We have the option to move the form for creating a new recipe to a separate page. In doing so, we'll leave a convenient button for creating a new recipe on the recipe.html file.

To get started, let's create a fresh file named new-recipe.html. You'll find that it's going to look quite similar to what we had in recipes.html. So, go ahead and copy that piece of code and transfer it to the new file from the very beginning.

The file's name in the example below doesn't correspond to the file's name in our project.

new_recipe.html

new_recipe.html

copy

Now we need to create a route first to actually render this template.

# main.py

@app.route("/recipes/new/", methods=["GET", "POST"])
def new_recipe():
    if request.method == "POST":
        recipe_title = request.form["title"]
        recipe_description = request.form["description"]
        new_recipe = Recipe(title=recipe_title, 
    description=recipe_description, author="Joey")
        db.session.add(new_recipe)
        db.session.commit()
        return redirect("/recipes/")
    else:
        return render_template("new_recipe.html")

Now let's add a button to the recipe.html template for 'New recipe'.

<h1>All recipes</h1>
<a class="btn btn-success float-right" href="/recipe/new/">New recipe</a>

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 7
some-alt