python - Django Templates: How to Pass PK/IDs of Displayed Objects Back to the Views.py file from the Template? -



python - Django Templates: How to Pass PK/IDs of Displayed Objects Back to the Views.py file from the Template? -

i want create basic comment , posting scheme on each user’s page. in views.py, phone call queryset of posts on user’s page , phone call ‘postset’. in template, loop through entire queryset , extract postcontent, postdate, , pk/id of post each post in postset queryset. under each post, display form entering comment. problem want somehow pass {{ postset.pk }} variable corresponding post user filling in commentform views.py file can store inputted comment under right post belongs to. how can this? specifically, how can django understand post each commentform located under post entered comment should attached via foreignkey?

thanks in advance help. i'm having hard time this. appreciate it.

<ul> {% postset in postset %} <br>{{ postset.postcontent }} {{ postset.postdate }} {{ postset.pk }} </br> <form action="/myapp/{{url_paramforurl}}/" method="post"> {% csrf_token %} {{ commentform.commentcontent }} <input type="submit" value="comment" /> <ul> {% comment in postset.postcomment_set.all %} <br> {{ comment.comment }} {{comment.postcommentdate }} {% endfor %}</ul> {% endfor %} </ul>

as data, can either pass in url, or in form.

for example, might design url comment form posts includes postset id, example: /myapp/post/<id>/<postset_id>/add_comment/. it's simple matter of passing values in {% url %} tag in template, , using them in view.

alternatively, although don't solution much, add together hidden input contains postset id:

<input type="hidden" name="postset_id" value="{{ postset.id }}">

and request.post in view.

python html django django-views

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -