jquery経由でバックエンドに投稿しています。私はまず誓約書がすでに作成されているかどうかを確認します。そうでない場合は、作成します。
@csrf_exempt
def pledgeReceive(request):
fname = request.POST.get('fname', '')
lname = request.POST.get('lname', '')
participantName = request.POST.get('participantName', '')
participantID = request.POST.get('participantID', '')
ppl = request.POST.get('ppl', '')
maxi = request.POST.get('maxi', '')
sponsor = fname + ' ' + lname
participant_obj = Participant.objects.get(pk = participantID)
try:
pledge = Pledge.objects.get(sponsor = sponsor, participant = participant_obj, pledge_amount = ppl, max_pledge_amount = maxi, datetime = datetime.now())
except Pledge.DoesNotExist:
pledge = Pledge(sponsor = sponsor, participant = participant_obj, pledge_amount = ppl, max_pledge_amount = maxi, datetime = datetime.now())
pledge.save()
response = HttpResponse()
response.content = serialized_obj = serializers.serialize('json', [ pledge, ])
response['Content-Type'] = 'application/json'
return response
500 内部サーバー エラーが発生します。次のトレースバックを使用します。
ValidationError at /pledgeReceive/
No exception supplied
Traceback:
File "/home/vtrelayc/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/vtrelayc/lib/python2.6/site-packages/django/views/decorators/csrf.py" in wrapped_view
77. return view_func(*args, **kwargs)
File "/home/vtrelayc/projects/relay/relayapp/views.py" in pledgeReceive
461. pledge.save()
File "/home/vtrelayc/lib/python2.6/site-packages/django/db/models/base.py" in save
463. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home/vtrelayc/lib/python2.6/site-packages/django/db/models/base.py" in save_base
551. result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/home/vtrelayc/lib/python2.6/site-packages/django/db/models/manager.py" in _insert
203. return insert_query(self.model, objs, fields, **kwargs)
File "/home/vtrelayc/lib/python2.6/site-packages/django/db/models/query.py" in insert_query
1593. return query.get_compiler(using=using).execute_sql(return_id)
File "/home/vtrelayc/lib/python2.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
911. for sql, params in self.as_sql():
File "/home/vtrelayc/lib/python2.6/site-packages/django/db/models/sql/compiler.py" in as_sql
872. for obj in self.query.objs
File "/home/vtrelayc/lib/python2.6/site-packages/django/db/models/fields/__init__.py" in get_db_prep_save
873. return connection.ops.value_to_db_decimal(self.to_python(value),
File "/home/vtrelayc/lib/python2.6/site-packages/django/db/models/fields/__init__.py" in to_python
850. raise exceptions.ValidationError(msg)
Exception Type: ValidationError at /pledgeReceive/
私は例外を提供していますが、except Pledge.DoesNotExist:
?