PythonTip >> 博文 >> Django python

django错误:TypeError: not enough arguments for format string

zihua 2014-02-17 15:02:00 点击: 954 | 收藏


sql = "select id,dataflow_name,date_format(from_unixtime(dataflow_datekey),'%%Y-%%m-%%d') as dataflow_date from dataflow_info"        
dataflow_lists = Info.objects.raw(sql) 
for dataflow in dataflow_list:
    print dataflow.dataflow_date
出现错误,TypeError: not enough arguments for format string。

用户输入那边,一个字符串型的参数,含有“%”,这个“%”造成python认为此字符串有format倾向,出现错误。

%%取代%可以解决这个问题。

sql = "select id,dataflow_name,date_format(from_unixtime(dataflow_datekey),'%%Y-%%m-%%d') as dataflow_date from dataflow_info"        
dataflow_lists = Info.objects.raw(sql) 
for dataflow in dataflow_list:
    print dataflow.dataflow_date
原文链接:http://www.tuicool.com/articles/bqQvyuN

作者:zihua | 分类: Django python | 标签: django python | 阅读: 954 | 发布于: 2014-02-17 15时 |