DJango报错
ERROR:default:Traceback (most recent call last): File "/data/venv4archer/lib/python3.6/site-packages/django/core/handlers/base.py", line 132, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/data/venv4archer/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view return view_func(*args, **kwargs) File "/data/opt/archer_product_20181019/sql/views.py", line 1123, in modifydatasourceapply applyusername=datasourceapply.objects.filter(id=int(Datasourceapplyid)).values('user_name') ValueError: invalid literal for int() with base 10: ''
报错原因:
post传送过来的变量为空。
Datasourceapplyid = request.POST.get("datasourceid", "") print ('Datasourceapplyid', Datasourceapplyid) ValueError: invalid literal for int() with base 10: '' [26/Oct/2018 18:39:10] "POST /modifydatasourceapply/ HTTP/1.1" 500 12987 Datasourceapplyid
解决方法:
修复post变量传入。
报错时,var datasourceid = $(“#datasource_id”).val();写成了var datasourceid = $(“#datasourceid”).val();,进而导致传输的变量为空值。
<form method="post" role="form"> {% csrf_token %} <div class="form-group"> <input type="hidden" class="form-control" id="datasource_id" name="datasourceid" value={{ datasourceDetail.id }} > </div> $("#btn-submitsql").click(function () { var datasourceid = $("#datasource_id").val(); var app_name = $("#app_name").val(); var env = $("#env").val(); var db_name = $("#db_name").val(); var db_privs = $("#db_privs").val(); var username = $("#username").val(); var port = $("#port").val(); var password = $("#password").val(); var ip_addr = $("#ip_addr").val(); $.ajax({ type: "post", async: false, url: "/modifydatasourceapply/", dataType: "json", data: { datasourceid: datasourceid, app_name: app_name, env: env, db_name: db_name, db_privs: db_privs, username: username, port: port, password: password, ip_addr: ip_addr },