A
A
Alexey Belov2018-06-11 21:51:11
Django
Alexey Belov, 2018-06-11 21:51:11

How to do event handling in Django Template?

How can I add a user to a group by clicking on a button, yes it should be request.user and group.add () in the view

from django.contrib.auth.models import Group
group = Group.objects.get(name='groupname')
user.groups.add(group)

But how to make a view and put processing on the link
<li>Также вы можете <a>cтать тренером</a>, и получить дополнительные возможности.</li>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2018-06-12
@Alenorze

If you're seriously asking a question (I'm asking because it's trivial, as commenters have pointed out before), then keep in mind that links generate a GET request. GET requests should not change the state of the application (for a variety of reasons, for example, because the link may be preloaded by a browser, or a browser extension, or a search engine).
Therefore, if you really need a link, then you need to create a form with the POST method, and when you click the link, send this particular form (for example, using javascript).

T
timur14, 2018-06-11
@timur14

There are two options:
- the link has an href attribute ( htmlbook.ru/html/a/href) and its value should be the url that leads to the view
- and you can make an ajax request using js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question