There is a website where I loop elements of a table like this:

<ul> {% for topic in topics %} <li><a href="/topic/{{ topic.pk }}">{{ topic.subject}}<br /> { topic.text}}</a></li> {% endfor %} </ul> 

I want to add a button near each element, when clicked, which topic.subject, topic.text of this particular cell will be added to another earlier created table. Using only Django while doing this.

You can call a function in views.py by pressing a button, but how do you pass it into the subject u text? Maybe you can somehow build a post-request using this data. I have so far failed.

Thank you all in advance.

  • Need to add to another table on the same page without reloading it? Then you need to do this completely on the client side on js. - Xander
  • Not necessary. You can redirect to another page, if required. We need a method without js, maybe even a crutch, for now there is no time to figure it out. Or you can tell how to do it using the java script. - Sergey
  • {{ topic.text}} . And so, yes, here js + ajax is needed, most likely. - m0nte-cr1st0 2:38 pm

1 answer 1

I will answer myself, men. Did not without the help of one good developer.

 <input type="checkbox" name="{{topic.pk}}"> 

such or similar code is thrust into the loop. And after the entire list we make a button with input type="submit" . The entire cycle and button is wrapped in a <form> ... </form> . After that, a POST request by clicking to send the marked elements to the function in views.py . And there you can do anything with them.

So it goes.