Django Ajax post 500 internal error -
i hope can me, im trying make django post form without reloading page using ajax, im getting error 500 when submit, can me fix this, code:
models.py
class productoconcepto(models.model): producto = models.foreignkey(producto) orden = models.foreignkey(cobro) cantidad = models.floatfield()
urls.py
from django.conf.urls import patterns, include, url django.contrib import admin cobro import views urlpatterns = [ url(r'^cobro/agregar_concepto/$', views.addconcept_product, name='add_concepto'), ]
views.py
def addconcept_product(request): if request.method == 'post': if form.is_valid(): producto = request.post['producto'] orden = request.post['orden'] cantidad = request.post['cantidad'] productoconcepto.objects.create(producto=producto, orden=orden, cantidad=cantidad) return httpresponse('')
template
<div class="modal inmodal fade" id="mymodal1" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog modal-m"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"> <span aria-hidden="true">×</span> <span class="sr-only">cerrar</span> </button> <h3 class="modal-title">agregar nuevo concepto</h3> </div> <div class="modal-body"> <p>datos de concepto agregar:</p> <div class="doctorformstyle"> <form id='formulario-modal' method='post' enctype='multipart/form-data'> {% csrf_token %} <ul>{{form2.as_p}}</ul> <!-- rendered form2 fields: <select id="id_producto" name="producto"><option value="1" selected="selected">object</option></select> --> <!-- form2 fields: <select id="id_orden" name="orden"> <option value="1" selected="selected">object</option> </select> --> <!-- form2 fields: <input id="id_cantidad" name="cantidad" step="any" type="number"> --> <div class="row align-center"> <input type='submit' name="save1" value='guardar' class="btn btn-w-m btn-primary"/> </div> </form> </div> </div> </div> </div> </div> <script type="text/javascript"> $(document).on('submit', '#formulario-modal', function(e){ e.preventdefault(); $.ajax ({ type: 'post', url: '{% url 'add_concepto' %}', data: { producto: $('#id_producto').val(), orden: $('#id_orden').val(), cantidad: $('#id_cantidad').val(), csrfmiddlewaretoken: '{{ csrf_token }}', }, sucess:function(){ alert("ok"); } }) }); </script>
this error: post http://127.0.0.1:8000/cobro/agregar_concepto/ 500 (internal server error)
i think maybe missing in view, buy dont know that, cal me?
edit: traceback added
environment:
request method: request url: http://127.0.0.1:8000/cobro/agregar_concepto/
django version: 1.9.7 python version: 2.7.11 installed applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'entrada', 'cobro', 'catalogo', 'selectize', 'smart_selects') installed middleware: ('django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.common.commonmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.auth.middleware.sessionauthenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'django.middleware.clickjacking.xframeoptionsmiddleware')
traceback:
file "c:\python27\lib\site-packages\django\core\handlers\base.py" in get_response 158. % (callback.module, view_name))
exception type: valueerror @ /cobro/agregar_concepto/ exception value: view cobro.views.addconcept_product didn't return httpresponse object. returned none instead.
you view not complete: exception states: view cobro.views.addconcept_product didn't return proper httpresponse object.
return httpresponseredirect('/thanks/')
Comments
Post a Comment