(Django) How to implement a button in the template that triggers any method? [closed]

0

My question is regarding the implementation of buttons in any template. I want to click this button and do something, such as displaying a message on the screen. How can I do this? Here is an image of my application that I want to add an "exit" button that will say a trivial message like wow. image http://i61.tinypic.com/359w9r4.png

    
asked by anonymous 12.08.2015 / 17:31

2 answers

1

From what I understand you want to do this in Django. Well, if in your case you want to make a registration and after the registration display the message, my tip would be this:

And at the end of the registration function of your view you should add a render request, like this:

def nome_da_sua_view(request):
    # Código de cadastro aqui
    return render(request, 'thanks.html', {})

Remember that it should stay within the validation if it is a POST method, something like this:

 if request.method == 'POST':

Then you should add this redirect to your URLs:

urlpatterns = [
    url(r'^thanks/', 'nome_do_seu_app.views.nome_da_sua_view'),
]

Finally, inside your template folder, it should contain an HTML file called thanks.html.

    
13.08.2015 / 02:56
0

Thank you guys! I did a lot of gambiarras here, it was necessary to create a url that calls a view that performs the action. I implemented the view to list all the addresses already registered and then put the list in a template. This way when I click on the button "display entries" the screen of registered addresses is displayed immediately, this was done with Ajax. imagen1 http://i59.tinypic.com/2ho8mmv.png imagen2 http://i60.tinypic.com/2qi0h07.png

    
15.08.2015 / 01:21