Is there any trick or idea how to pass data using form etc.?
If I understand correctly, you want to use form
but a
tag.
Try this:
<div class="row">
{% csrf_token %}
{% for folder in folder_list %}
Folder title: <span id="titles" name="titles" >{{folder.title}}</span></p>
Date upload: <span id="date_upload" name="date_upload">{{folder.date_upload}}</span>
<form action="{% url 'view_gallery' %}" method="POST" id="form1">
<!-- This input won't be show -->
<input type="text" idd={{folder.id}} style="display:none">
<button type="submit">Open</button>
</form>
{% endfor %}
</div>
Then when you hit the Open
button, a POST
method will be made to url view_gallery
with params idd=123
. (example.com/view_gallery?idd=123)
Then it will work.
But I strongly recommend you to organize URLs like this:
- Declare <a> tag like:
<a href="{% url 'view_detail_gallery' folder.id %}">
- Change your URL’s pattern to something like:
example.com/view_gallery/:id
. Declare a new pattern URL:
path('gallery/<int:id>/', view_detail_gallery, name = 'gallery_detail'),
- Declare a new view in
views.py
:
@login_required(login_url='log_permission')
def view_detail_gallery(request, id):
if request.method == 'GET':
image = gallery_photos.objects.filter(gallery_info_id = id)
data = {'photos':image}
return render(request, 'view_detail_gallery.html', data)
You can create a new detail
HTML or not because as I can see, you didn’t do it and your code is still working (Hope so).