2

I added custom button into my app_index.html file:

<form action="{% url 'admin:index' %}">
    <input type="submit" value="{% trans 'Another Button' %}" 
name="_anotherbutton" />
</form>

I have simple function:

def printer():
    print('Some text')

How can I run this function using my custom button? Now it maps to admin:index but I would like it to run printer function and go to another view (or show alert message using jquery - I will think about it). Printer function is just an example - in real it will do some database search/modify database and go to result view.

1 Answer 1

1

You need to stop thinking in terms of functions. You need to think in terms of views and URLs. The only way your frontend can communicate with your backend is via a view called from a URL. So, you need to call your function from a view, and associate a URL with it, which your button calls.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.