Django错误:需要元组或struct_time参数 - javascript

我正在编写一个获取2个变量的代码,它们分别是showdate和viewtype。可变数据都是通过POST方法通过JavaScript发送的。

viewtype = send an srt

showdate = send a date from javascript

在此代码中,我手动定义了变量,因为最后的操作是查询数据库,仅返回以基于showdate和viewtape的参数生成的参数开头的“事件”,如下所示:

{"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在“事件”中包含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

参考方案

您的代码有多个问题,最初导致该问题的是您的jsToPythonTime方法不返回任何内容的事实。

re.findall返回匹配项,因此它永远不会等于整数,因此也永远不会输入if / elif语句。

time.mktime需要一个长度为9的元组的单个参数。

然后,您继续将您认为的时间转换为字符串,然后再转换为使我感到困惑的整数。

Javascript-从当前网址中删除查询字符串 - javascript

单击提交按钮后,我需要从网址中删除查询字符串值。我可以用jQuery做到这一点吗?当前网址:siteUrl/page.php?key=value 页面提交后:siteUrl/page.php 实际上,我已经从另一个带有查询字符串的页面着陆到当前页面。我需要在页面首次加载时查询字符串值以预填充一些详细信息。但是,一旦我提交了表格,我就需要删除查询字符串值。我已…

Mongo汇总 - javascript

我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …

如何在JQuery中操作JSONArray - javascript

我有一个php函数,它以JSON返回此代码{"0":{"title":"Dans l\u2019appartement"},"1":{"title":"A l\u2019a\u00e9roport - D\u00e9part de B\u00e9at…

JavaScript中的字符串评估函数 - javascript

            JavaScript中是否有任何内置函数,例如Python中的eval内置函数?注意:eval函数将方程式作为字符串并返回结果。例如,假设变量x为2,则eval("2x+5")返回9。 参考方案 是的,JavaScript中也有eval函数。此外,该声明应有效用于评估,即eval("2*x+5"…

在两个值之间匹配并返回正则表达式 - javascript

我正在尝试使用正则表达式从字符串中获取值,该值是tt="和"&之间的文本的值因此,例如,"tt="Value"&"我只想从中得到单词"Value"。到目前为止,我已经有了:/tt=.*&/这给了我"tt=Value"&,然后,要…