Django報錯ValueError: invalid literal for int() with base 10:
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 },
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2217735/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- django 報錯:ValueError: The database backend does not accept 0 as a value for AutoField.DjangoErrorDatabase
- dbfread報錯ValueError錯誤解決方法Error
- 解決tensorboard報錯ValueError: Duplicate plugins for name projectorORBErrorPluginProject
- minio連線失敗報錯ValueError: path in endpoint is not allowedError
- iOS 上架報錯 This bundle is invalid 或 Invalid Image PathiOS
- Django 報錯 TemplateDoesNotExistDjango
- React報錯之Element type is invalidReact
- mybatis 報錯: Invalid bound statement (not found)MyBatis
- Django報錯django.utils.datastructures.MultiValueDictKeyErrorDjangoASTStructError
- Django 報錯資訊總結Django
- 1.python報錯:TypeError: 'int' object is not subscriptablePythonErrorObject
- error: invalid type argument of unary ‘*‘ (have ‘int‘) *__first = __tmp;Error
- Java - XML字元支援報錯An invalid XML characterJavaXML字元
- kafka報錯:InvalidReceiveException: Invalid receive (size = 1195725856 larger than 104857600)KafkaException
- Eclipes中使用BASE64Encoder及BASE64Decoder報錯
- svn報錯“Previous operation has not finished; run 'cleanup' if it was int
- invalid conversion from ‘LRUCache*‘ to ‘int‘ [-fpermissive] /new的使用
- oracle ORA-01722 報錯 "invalid number"Oracle
- Django使用終端建立superuser報錯。Django
- python: invalid value encountered in divide以及invalid value encountered in double_scalars報錯PythonIDE
- django3整合django-mdeditor報 ‘X-Frame-Options‘ 錯誤Django
- Elasticsearch 6 建立索引報錯 invalid_index_name_exception Invalid index name [testDemo], must be lowercaseElasticsearch索引IndexException
- Python中遇到奇怪的錯誤ValueError:badmarshaldataPythonErrorLDA
- 11g匯出報錯:EXP-00106: Invalid Database Link PasswordsDatabase
- Unable to unwrap data, invalid status [CLOSED]-服務端webSocket報錯服務端Web
- Mingw GCC 編譯OpenCV報錯: Project files may be invalidGC編譯OpenCVProject
- `jsonb` 報錯 `invalid input syntax for type timestamp with time zone ““JSON
- Django(21)migrate報錯的解決方案Django
- sqlplus / as sysdba報錯ORA-01017: invalid username/password; logon deniedSQLGo
- 前端base64圖片下載報錯(已解決!!!)前端
- 華為支付購買token的verify介面報錯Token is expired or invalid
- Maven專案報錯invalid LOC header (bad signature)MavenHeader
- a-better-way-to-find-literal-sqls-in-oracle-10g/SQLOracle
- django中出現 錯誤 Errno 10053Django
- 小程式 · 報錯:Error: errCode: -501007 ,errMsg: Invalid Key Name (__keyPath)Error
- Django2.2 報錯:UnicodeDecodeError 解決方法DjangoUnicodeError
- Django出現DisallowedHost at / Invalid HTTP_HOST headerDjangoHTTPHeader
- Mysql中 int(10)和int(11)的區別MySql