Skip to content
Advertisement

Flask – how to call python function with parameters in button?

I am working on a notification system on my website. I decided to make a model in the database for them. I also made a function in views.py that takes an argument of a user that is receiving a notification and the type of notification. Here is the code:

JavaScript

Now I want to be able to send the user a notification when someone invites them. I was thinking about calling the python function when someone presses the button but I don’t know how to code it.

I came up with something like this but it doesn’t work:

JavaScript

Advertisement

Answer

url_for() in Flask Jinja templates does not work like that. It forms a URL to a specific resource, which means you can not pass Python code as a parameter. The option that comes to my mind first is to use URL parameters for passing data to your route function.

JavaScript

So that your HTML would look like that:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement