2

My question is basically this question: Call Django on HTML button click

To summarize: in Django, how do you call a function after clicking a button?

I followed the answer in the above link, however, whenever I click on the button it takes me to the URL of /actionUrl, which I do not want. I simply want the function I have to be called when the button is clicked.

Any help would be appreciated because I do not have enough rep to comment on that post.

1 Answers1

0

As the other link says, you'll have a url that connects the button to a view. Whatever you have in your action from your HTML form is what should be in your url. I'm not sure if this will answer your problem, but the next step is to create a view with your function that redirects to the webpage that you wish to stay on. For example, this view might look like:

def sort(request):
    if request.method == "GET":
        function()
        return redirect('/webpage')

You can reference this stack for more info about redirect. And here the django reference for redirect.