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 date picker or drop down menu if i create a forms.py file.
I have created the template and i can access it and it formats exactly how i want, however I can't workout how to get it to POST. The idea is to take the data in the form and insert it into a Postgres table.
Template submit.py
{% extends 'website/header.html' %}
{% block content %}
<p><b>Submit Job</b></p>
<form action="" method="post">
{% csrf_token %}
<b>Select Asset to transcode</b>
<p>Material ID:
<input type="text" name="material_id" size="30" value="" id="keyword"/>
</p>
<p>Profile:
<select name="workflow">
<option value="">Select a transcode Profile</option>
{% for i in object_list %}
<option value="{{ i.name }}">{{ i.name }}</option>
{% endfor %}
</select>
</p>
<script>
$(function() {
$( "#start_datepicker" ).datepicker({
dateFormat: 'dd-mm-yy'
});
});
</script>
<p>License Start Date: <input type="text" id="start_datepicker" name="start_date"></p>
<script>
$(function() {
$( "#end_datepicker" ).datepicker({
dateFormat: 'dd-mm-yy'
});
});
</script>
<p>License End Date: <input type="text" id="end_datepicker" name="end_date"></p>
<p>
<input type="submit" name="submit" />
</p>
</form>
{% endblock %}
Views.py
from django.shortcuts import render
def submit(request):
if request.method == 'POST':
material_id = request.POST['material_id']
workflow = request.POST['workflow']
start_date = request.POST['start_date']
end_date = request.POST['end_date']
return render(request, 'submit/submit.html')
else:
return render(request, 'submit/submit.html')
Here is the error I am getting:
Method Not Allowed (POST): /submit/
[08/Feb/2017 17:28:49] "POST /submit/ HTTP/1.1" 405 0
What am I doing incorrectly?
EDIT
Here are the URL files:
mysite url.py
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('website.urls')),
url(r'^submit/', include('submit.urls')),
url(r'^repo/', include('asset_db.urls')),
]
submit url.py
from django.conf.urls import url
from django.views.generic import ListView
from asset_db.models import Profiles
urlpatterns = [
url(r'^$', ListView.as_view(queryset=Profiles.objects.all().order_by("id"), template_name='submit/submit.html')),
]