I know the title is maybe confusing, but let me clarify my problem.
I have an Animal
model with simply a name
field in it.
In my HTML template, I list each instance of Animal
in an a
element (display order may vary).
view.py:
def index(request):
animals = Animal.objects.all()
return render(request, 'index.html', {'animals': animals})
index.html:
{% for animal in animals %}
<a>animal.name</a>
{% endfor %}
Output is something like this:
My question is, when the user clicks on an animal, I have to perform certain actions in the database. But how can I know which animal did he click ? I don't want to get the client-side text with javascript, because this is not secure and the user can change it by inspecting the element.
I simplified my problem with animals, but in reality it is more complicated than this and I really need to find a secure way to get the correct clicked animal, even if the user changed the text or the HTML class or ID or something like this.
Edit: I don't want either to use any other method that allows the user to change html from his browser
question from:
https://stackoverflow.com/questions/65672120/django-how-to-link-a-client-side-component-with-a-server-side-information 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…