学习django各种奇葩错误日志

1.Page not found (404)

Request Method: GET
Request URL: http://127.0.0.1:8000/login.html/

原因,前端url或者后台url填写错误,尤其注意/

2.Cannot resolve keyword u'slug' into field error 

原因:orm查询时数据库的字段名称填写错误

3. 301,302重定向次数过多

  原因:get请求不能一开始就redirect重定向,必须有response

3.浏览器,路由分发,谷歌浏览器自动给你添加斜杠

解决办法:清除历史记录cookie之类的,主要是浏览器的自动记忆功能

4:ValueError at /add_classes.html

The view myapp.views.inner didn't return an HttpResponse object. It returned None instead.
原因:没返回response

5.url的正则表达式千万不要写成^不加$,否则的话,他会任意匹配,这是一个万能匹配公示,他会匹配不到你想要的url,当查看response之后发现返回对象不对,肯定我是url分发问题,这时,你就查看哪个url返回此对象

5.djiango 书写原生sql语句是,调用数据库时间的格式化函数是,请注意参数一定要双%
如下

'select aid, count(aid) as num,date_format(create_time, "%%Y-%%m") as ctime from repository_article group by date_format(create_time, "%%Y-%%m")')

我被这坑整整浪费了2个小时,真特么太坑了,估计要经过python的解释器,不些双%号,python就会将%号解释为占位符了

原文地址:https://www.cnblogs.com/xc1234/p/8335331.html