Skip to content Skip to sidebar Skip to footer

Django Form Using Html Template

I'm new to Django and I have been trying to get this form to POST. I have read the documentation on forms but i'm a bit confused by it as I am not sure how to implement the Jquery

Solution 1:

You are using ListView for this url. But ListView allowed only GET request. That's why when it get request with POST method. It is giving error METHOD NOT ALLOWED. Create a view for this url in your views.py and define get and post method.

Solution 2:

Check that your urls.py file has something like

from django.conf.urls import patterns, url

urlpatterns = patterns('',
    url(r'^submit/$', 'yourapp.views.submit'),
)

datepicker is not related to the issue. Most likely you post to another view. Check all urls and view names.

Solution 3:

You don't have a view mapped to your submit URL. Your only URL under /submit is a ListView.

Solution 4:

As suggested creating a view and not using ListView fixed the issue.

Updated submit views.py

from django.shortcuts import render
from asset_db.models import Profiles


defsubmit(request):
    profiles = Profiles.objects.order_by('-id')
    context = {'profiles': profiles}
    return render(request, 'submit/submit.html', context)


defsuccess(request):
    profiles = Profiles.objects.order_by('-id')
    context = {'profiles': profiles}
    return render(request, 'submit/success.html', context)

Updated template submit.html

{% extends 'website/header.html' %}
{% block content %}
    <p><b>Submit Job</b></p><formaction="{% url 'success' %}"method="post">
    {% csrf_token %}
        <b>Select Asset to transcode</b><p>Material ID:
            <inputtype="text"name="material_id"size="30"value=""id="keyword"/></p><p>Profile:
            <selectname="workflow"><optionvalue="">Select a transcode Profile</option>
                {%  for i in profiles %}
                    <optionvalue="{{ i.name }}">{{ i.name }}</option>
                {% endfor %}
            </select></p><script>
            $(function() {
                $( "#start_datepicker" ).datepicker({
                    dateFormat: 'dd-mm-yy'
                });
            });
        </script><p>License Start Date: <inputtype="text"id="start_datepicker"name="start_date"></p><script>
            $(function() {
                $( "#end_datepicker" ).datepicker({
                    dateFormat: 'dd-mm-yy'
                });
            });
        </script><p>License End Date: <inputtype="text"id="end_datepicker"name="end_date"></p><p><inputtype="submit"name="submit" /></p></form>
{% endblock %}

Webserver results:

[09/Feb/2017 08:55:22] "GET /submit/ HTTP/1.1"2003300
[09/Feb/2017 08:55:29] "POST /submit/success/ HTTP/1.1"2002043

I used Django Tutorial part 3 for help with creating the context. Thanks for pointing me in the correct direction!

Post a Comment for "Django Form Using Html Template"