Day80

上节回顾:

  评论:

    1 提交跟评论

 

    2 显示跟评论

      ---render显示

      ---ajax显示

    3 提交子平论

  

    4 显示子平论

      ---render显示

      ---ajax显示

    

两个Bug:

  (1)先提交子平论,不刷新页面,再次提交根评论,会把评论提交为子平论

  (2)先点击回复,在删除内容的@xxx,则再次提交评论,为子平论。

今日内容

ajax显示评论

 

ajax   success function(data){    还有 error function(){      还有finnaly function()  {

            }              }                     }

jquery 可以找到相应标签.append()增加新标签

 

 

import datetime

datetime.date    datetime.time      datetime.datetime      datetime.timedelta进行时间相加相减时,用的类。他有year,moth,days等参数。用这个对象,与now()对象相加相减。

datetime.datetime.now().strftime(''%Y-%m-%d %H:%M')

因为时间存储的是datatime.datetime的格式,如果我们 return json.dumps('time'),则会报错,因为json只能序列化到字典。

若用return JsonResponse(‘time’),则内部他会给我们序列化。

但是如果我们自己写,strftime则可以格式化时间为字符串

 

在JS中要使用模板语言时,尽量不用'{{}}',而是写个div,设置属性,去找。

ajax显示跟评论

 

评论树思路

111

|  444

|    |

222    555

同时得到一个queryset对象,因为他是个对象,不能直接用JsonResponse返回,需要用list强转为列表。

return JsonResponse(ret,safe=False)  当我们返回的ret是一个列表时,需要将safe设置为False

posted on 2018-10-15 14:50  castiel_lee  阅读(68)  评论(0)    收藏  举报

导航