[Answer]-How to submit POST request to '"current_url"/submit' in HTML's form action using Django templates?

1👍

✅

It’s a bad idea to try and parse/modify the existing URL. But there’s no reason to. Your template presumably already has access to the post itself, so you should use this to construct the URL via the normal {% url %} tag.

<form action="{% url "submit_comment" post_id=post.id %}" method="POST">

assuming the post is passed to the template as post and there is a urlconf that looks like this:

url(r'(?P<post_id>\d+)/submit/$', views.submit_comment, name='submit_comment'),

Leave a comment