0
我正在研究一個獲取2個變量,showdate和viewtype的代碼。通過POST方法通過JavaScript發送變量數據。Django錯誤:需要Tuple或struct_time參數
viewtype = send an srt
showdate = send a date from javascript
在這段代碼中,我定義手動可變因素,作爲最後的操作是查詢數據庫,僅返回,在這是基於showdate相似和viewtape在JSON作爲生成的參數開始「事件」下一個:
{"events": [["19", "Dinner," "02 \/02 \/2016 9:00" "02 \/02 \/2016
16:30", "0", 0,0, null , 1, null, ""], ["20", "Meeting", "02 \/03 \/
2016 18:30" "02 \/03 \/2016 19:30", "0", 0, 0, "6", 1, "LOL", ""]],
"issort": true, "start": "02 \/01 \/2016 00:00", "end": "02 \/07 \
/2016 23:59 "," error ": null}
在這個例子中,我們看到JSON在「events」中包含2個事件。 然後我顯示錯誤狀態和我的代碼: 我希望你能幫助我,謝謝。
Traceback:
File "/home/zalar1/virtualenvs/go/lib/python3.4/site-packages/django
/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/home/zalar1/virtualenvs/go/lib/python3.4/site-packages/django
/core/handlers/base.py" in get_response
147.response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/zalar1/virtualenvs/go/Project1/Apps/Calendario/views.py"
in loadActivities
123. ldac = listCalendar(showdate, viewtype)
File "/home/zalar1/virtualenvs/go/Project1/Apps/Calendario/views.py"
in listCalendar
71. calc1 = int(time.strftime("%d", pytTime))
Exception Type: TypeError at /agytno/LODT
Exception Value: Tuple or struct_time argument required
views.py
def listCalendar(day, Dtype):
pytTime = jsToPythonTime(day)
if Dtype == "month":
st = time.mktime(
0, 0, 0, time.strftime("%m", pytTime),
1, time.strftime("%Y", pytTime)
)
et = time.mktime(
0, 0, -1, time.strftime("%m", pytTime)+1,
1, time.strftime("%Y", pytTime)
)
elif Dtype == "week":
calc1 = int(time.strftime("%d", pytTime))
calc2 = int(time.strftime("%w", pytTime))
if calc2 == 0:
calc2 = 7
monday = srt(calc1 - calc2 + 1)
# suppose first day of a week is monday
st = time.mktime(
0, 0, 0, time.strftime("%m", pytTime),
monday, time.strftime("%Y", pytTime)
)
et = time.mktime(
0, 0, -1, time.strftime("%m", pytTime),
monday+7, time.strftime("%Y", pytTime)
)
elif Dtype == "day":
st = time.mktime(
0, 0, 0, time.strftime("%m", pytTime),
time.strftime("%d", pytTime),
time.strftime("%Y", pytTime)
)
et = time.mktime(
0, 0, -1, time.strftime("%m", pytTime),
time.strftime("%d", pytTime)+1,
time.strftime("%Y", pytTime)
)
return listCalendarByRange(st, et)
tiempoConv.py
def jsToPythonTime(jsDate):
matches = re.findall('(\d+)/(\d+)/(\d+)\s+(\d+):(\d+)', jsDate)
matches2 = re.findall('(\d+)/(\d+)/(\d+)', jsDate)
if matches == 1:
ret = time.mktime(
matches[4], matches[5], 0,
matches[1], matches[2], matches[3]
)
return ret
elif matches2 == 2:
ret = time.mktime(0, 0, 0, matches2[1], matches2[2], matches2[3])
return ret
您應該發佈與您的問題相關的唯一代碼 – Sayse
您在'listCalender'方法中'pyTime'的值是什麼?例外的原因是'pyTime'沒有'time.strftime'所需的正確格式的值。 –
@Sayse你好朋友,對不起,我認爲在這種情況下,到了有代碼的末尾,我把所有的代碼放在相關的位置。 –