2
當我嘗試運行此視圖/函數時,出現以下錯誤execute() first
。Python錯誤:執行()第一個
def homepage(request, parem1, parem2):
# open sql connection
cursor = connection.cursor()
if parem1 == 'p':
if parem2 == 'all':
cursor.execute((" SELECT eventname, id, party, DATE_FORMAT(eventdate, GET_FORMAT(DATE,'EUR')) FROM mainapp_eventdetails ORDER BY eventdate DESC "))
else:
cursor.execute((" SELECT eventname, id, party, DATE_FORMAT(eventdate, GET_FORMAT(DATE,'EUR')) FROM mainapp_eventdetails WHERE party = '" + parem2 + "' ORDER BY eventdate DESC "))
else:
if parem2 == 'all':
cursor.execute((" SELECT eventname, id, party, DATE_FORMAT(eventdate, GET_FORMAT(DATE,'EUR')) FROM mainapp_eventdetails ORDER BY eventdate DESC "))
elif parem2 == 'APR':
cursor.execute((" SELECT eventname, id, party, DATE_FORMAT(eventdate, GET_FORMAT(DATE,'EUR')) FROM mainapp_eventdetails WHERE eventdate between '2011-4-1' AND '2011-5-1' ORDER BY eventdate DESC "))
datalist = [memedetails for memedetails in cursor.fetchall()]
# close sql connection
cursor.close()
connection.close()
# group by eventdate
datalistsorted = []
# i dont like how this part depends on the sequence of columns retrieved in the above SQL.
for k, g in groupby(datalist, key=lambda x:x[3]):
datalistsorted.append((k,[(i[0],i[1],i[2]) for i in g]))
return render_to_response('base.html', {'eventlist': datalistsorted, 'parem2': parem2.upper()})
但如果我是這一行更改elif parem2 == 'APR':
到else:
,它工作正常。
這是爲什麼,我怎樣才能讓我的elif
工作? (下面有更多的條件,但我省略了它爲簡單起見)
你是對的,它與我的parem2解析在'四月'在較低的帽子,因此它沒有打。謝謝。愚蠢的錯誤。 – super9 2011-04-06 09:14:33
實際上它有一個很好的理由爲什麼會拋出一個錯誤?你可以簡單地說:*好吧,沒有查詢,這很好,對我來說工作較少...... *我不明白爲什麼這會引發異常。 – 2017-01-25 20:59:37