Home > OS >  Python Flask give argument to url
Python Flask give argument to url

Time:10-18

How can I pass the id of my event object.

 <div class="row">
     {% for event in events %}
    <div class="col">
<div class="card" style="width: 18rem;">
  <img src="https://tailwindcss.com/img/card-top.jpg" class="card-img-top" alt="...">
  <div class="card-body">
    <h5 class="card-title">{{event['title']}}</h5>
    <p class="card-text">{{event['description']}}</p>
      <h10 class="card-title">Start date: {{event['date']}}</h10>
    <a href="/participate/{event['id']}" class="btn btn-primary">Participate</a>
  </div>
</div>

    </div>
    {% endfor %}

With my python code i try to get the id from the button. My python code:

@app.route("/participate/<id>")
def participate(id):
    if session.get("email"):
        print(id)
        mail = setupMail()


        return redirect(url_for("home"))
    else: return redirect(url_for("login"))

CodePudding user response:

You wrote

{event["id"]}

with only one curly bracket. Try

{{event["id"}}

at your button instead, and replace the print statement in your python code by

app.logger.root.warning(id)

(print doesn’t work in flask)

  • Related