django编码中常见错误

1.在编写django代码时,启动服务器的时候报了两次不同的错误。后来发现两个问题都是指缩进的问题。我使用的是sublime编程,换行直接使用tab,导致代码格式不严谨。没办法只能换python的编译器重新修改了一下缩进

inconsistent use of tabs and spaces in indentation

unindent does not match any outer indentation level 

 

 2.打开对应链接例如:http://127.0.0.1:8000/index/,报了类型错误,一开始百思不得其解,翻了下代码没错啊。后来发现是没有在cmd中启用服务,可以说是非常粗心了。

 启用服务命令:python3 manage.py runserver

 3.报错:AttributeError: 'WSGIRequest' object has no attribute 'get'

我在编写代码时username = request.get('user','') #读取浏览器session,代码有误,将session补上就好了

正确格式:username = request.session.get('user','') #读取浏览器session

 

4.django连接mysql时,如果使用的是python2,则需要下载mysql-python。如果使用的是python3,则需要安装pymysql驱动。

python3安装驱动:pip install pymysql

 

posted @ 2017-06-07 11:03  buerq  阅读(740)  评论(0)    收藏  举报