PUT and DELETE Django
<p>I relatively new in django and python and now for a couple of days i'm trying to figure how to send PUT and DELETE requests throught django forms.</p>

<p>I found this topics:
<a href="https://baxeico.wordpress.com/2014/06/25/put-and-delete-http-requests-with-django-and-jquery/" rel="noreferrer">https://baxeico.wordpress.com/2014/06/25/put-and-delete-http-requests-with-django-and-jquery/</a></p>

<p><a href="https://stackoverflow.com/questions/30461839/sending-a-delete-request-from-a-form-in-django">Sending a DELETE request from a form in Django</a></p>

<p>But the way this topics solve this problem seams not easy for me. So question is - is there are any easy way to send PUT and DELETE requests throught forms in Django.</p>

<p>For now i have this:</p>

<p>views.py</p>

<pre><code>class AllRoutes(View):

model = Schedule
template_name = 'trains_schedule/all_routes.html'

def get(self,request,train_id=None):
    if train_id:
        train = Schedule.objects.get(pk=int(train_id))
        context = {'train':train}
    else:
        context = {'schedule_list':Schedule.objects.all()}
    return render(request,'trains_schedule/all_routes.html',context)

def delete(self,request,train_id=None):
    route = get_object_or_404(Schedule, pk=train_id)
    response = u'Successful delete route {}'.format(route.display_name())
    route.delete()
    return HttpResponse(response)
</code></pre>

<p>urls.py</p>

<pre><code>urlpatterns = [
url(r'^trains/(?P&lt;train_id&gt;[0-9]+)?$', views.AllRoutes.as_view(), name='trains')]
</code></pre>

<p>all_routes.html</p>

<pre><code>{% if schedule_list %}
&lt;h3&gt;{{ "List of all train routes" }}&lt;/h3&gt;
&lt;ul&gt;
{% for train_route in schedule_list %}
    &lt;li&gt;&lt;a href="{% url 'trains' train_route.id %}"&gt;{{ train_route.display_name }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
&lt;/ul&gt;
{% else %}
&lt;p&gt;&lt;/p&gt;
{% endif %}

{% if train %}
&lt;h1&gt;{{ train.train }}&lt;/h1&gt;

&lt;h3&gt;{{ "Route info" }}&lt;/h3&gt;
{{ train.display_train }}

&lt;h3&gt;{{ "Train info" }}&lt;/h3&gt;
{{train.display_train_info}}

&lt;form  method="delete"&gt;
{% csrf_token %}
&lt;input type="submit" value="Delete" /&gt;
&lt;/form&gt;
{% else %}
&lt;p&gt;&lt;/p&gt;
{% endif %}
</code></pre>

<p>Now it works this way:</p>

<ul>
<li>/trains/ show list of all trains routes and provide links to every route</li>
<li>/trains/12 - get() in views.py got route id and show information about this route</li>
</ul>

<p>And i want that when i pressing "delete" - view receive DELETE request.</p>

<p>I end with doing it this way:</p>

<pre><code>&lt;form  method="post"&gt;
{% csrf_token %}
&lt;input id="action_id" type="hidden" name="action" value="Delete"&gt;
&lt;input type="submit" value="Delete" /&gt;
&lt;/form&gt;
</code></pre>

<p>and in views.py i add handling of post request with action_id =="Delete"</p>

<p>But i want to make real DELETE and PUT request, not parse the POST request to understand that i need to do - delete or change route or add new one.</p>

<p>I understand that i need to change this part:</p>

<pre><code>&lt;form  method="delete"&gt;
{% csrf_token %}
&lt;input type="submit" value="Delete" /&gt;
&lt;/form&gt;
</code></pre>

<p>But i dont know how to do it.</p>