这篇博客主要总结的学习Django框架中,遇到的报错如何去解决问题:

1、decimal.InvalidOperation:

decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

在最后一行出现这样的报错:

decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

这个报错其实是数据库的数据长度超过了原本的长度

在models中定义类型是DecimalField中的(max_digits的范围,decimal_places=小数的长度)

分析:

因为max_digits的长度包括decimal_places的长度,数据库的数据经过运算超越了原本的最大长度,就会出现这种报错!

解决方法:

就是max_digits的长度增加,就能解决这个异常! (6月22日)

2、no such table: django_session

no such table: django_session

这个报错其实很简单的报错,意思就是数据库没有django_session,这个报错还是很好解决的。

解决方法:

就是在数据库中创建表,在pycharm 中的Terminal 中输入两个命令:

python manage makemigrations  先把要修改的内容登记到小本本上

python manage migrate   在数据库中创建表 这生成的是django的默认的表格

表格创建好,这个报错就能解决了。(6月26日)

3、 出现莫名其妙的 app01

我项目中的app名字并不是app01,可是运行python manage.py makemigrations的时候总是提示app01不是已安装的app

Applying admin.0003_auto_20180701_0233...Traceback (most recent call last):  
FiApplying admin.0003_auto_20180701_0233...Traceback (most recent call last): Field ...

解决办法:

找到自己的python环境下的site-packages/django/contrib/admin/migrations,把里面的py文件全删掉即可。

4、django.core.exceptions.FieldDoesNotExist: model has no field named <id>

使用了自定义的auth表,结果建表的时候提示admin找不到某个字段

解决办法:

找到自己的python环境下的site-packages/django/contrib/admin/migrations,把里面的py文件全删掉即可。

5、点击页面的按钮绑定AJAX提交数据但是后端收不到任何数据

这种情况一般是form表单中使用了 <button>提交</button>按钮,但是<button>< button/>按钮中没有明确指定type="button"。

解决办法:

使用AJAX提交数据的时候,提交数据的按钮可以使用如下方式:

1. 使用最保险的input标签, 并且指定type类型为button

<form>
...
<input type="button" value="提交">
</form>

2. 既然使用ajax提交数据就没必要再写form标签。

直接用div包裹获取用户输入的input标签即可。

3. 使用button按钮的时候,明确指定type类型为button, type一定不能省!!!

<button type="button">提交</button>

6、ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js

这个问题是用Google的浏览器的问题,配置jQuery的URL

django-debug-toolbar 默认使用的Google的地址,默认配置如下:

JQUERY_URL=‘//ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js’

解决方法:

在国内Google无法加载默认的jQuery的URL,我们就在settings.py中配置一下,我们特意选用了和原作者相同版本的jQuery:

DEBUG_TOOLBAR_CONFIG={
'JQUERY_UPL':'//cdn.bootcss.com/jquery/2.2.4/jquery.min.js'
}

也可以在Django项目中使用了jquery的话就可以直接将这一设置为空,那么django-debug-toolbar就会使用你项目中用到的jquery:

DEBUG_TOOLBAR_CONFIG={
'JQUERY_URL':'',
}
#不用改源码,在settings.py中加这个配置项就可以

python3 Django框架报错(备忘录)的更多相关文章

  1. ubuntu,装完PYTHON3 pip3 install 报错

    ubuntu,装完PYTHON3 pip3  install 报错CalledProcessError: Command 'lsb_release -a' returned non-zero exit ...

  2. Python3 pip命令报错:Fatal error in launcher: Unable to create process using '"'

    Python3 pip命令报错:Fatal error in launcher: Unable to create process using '"' 一.问题 环境:win7 同时安装py ...

  3. go语言,golang学习笔记3 用命令下载框架报错问题解决 设置环境变量

    go语言,golang学习笔记3 用命令下载框架报错问题解决 设置环境变量 下载安装:go get github.com/astaxie/beego 首页 - beego: 简约 & 强大并存 ...

  4. python---补充django中文报错(1),Django2.7使用sys.setdefaultencoding('utf-8'),以及使用reload(sys)原因

    SyntaxError at /blog/ news/story Non-ASCII character , but no encoding declared; see http://python.o ...

  5. Python3.x:报错POST data should be bytes, an iterable of bytes

    Python3.x:报错POST data should be bytes, an iterable of bytes 问题: python3.x:报错 POST data should be byt ...

  6. 在centos6.7通过源码安装python3.6.7报错“zipimport.ZipImportError: can't decompress data; zlib not available”

    在centos6.7通过源码安装python3.6.7报错: zipimport.ZipImportError: can't decompress data; zlib not available 从 ...

  7. django运行报错TypeError: object supporting the buffer API required

    运行django项目报错:TypeError: object supporting the buffer API required 解决方案: 将settings.py中数据库的密码改成字符串格式 源 ...

  8. python2中的unicode()函数在python3中会报错:

    python2中的unicode()函数在python3中会报错:NameError: name 'unicode' is not defined There is no such name in P ...

  9. Django独有报错的原因和解决

    RuntimeError at /login You called this URL via POST, but the URL doesn't end in a slash and you have ...

随机推荐

  1. bzoj 5094 [Lydsy1711月赛]硬盘检测 概率dp

    [Lydsy1711月赛]硬盘检测 Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 273  Solved: 75[Submit][Status][Dis ...

  2. 【HDU5772】String Problem [网络流]

    String Problem Time Limit: 10 Sec  Memory Limit: 64 MB[Submit][Status][Discuss] Description Input Ou ...

  3. 【Foreign】旅行路线 [倍增]

    旅行路线 Time Limit: 20 Sec  Memory Limit: 256 MB Description Input Output 仅一行一个整数表示答案. Sample Input 3 2 ...

  4. 【Foreign】数数 [打表][DP]

    数数 Time Limit: 10 Sec  Memory Limit: 128 MB Description Input 仅一行两个整数L,R Output 仅一行一个整数表示答案. Sample ...

  5. Codeforces Round #300 解题报告

    呜呜周日的时候手感一直很好 代码一般都是一遍过编译一遍过样例 做CF的时候前三题也都是一遍过Pretest没想着去检查... 期间姐姐提醒说有Announcement也自信不去看 呜呜然后就FST了 ...

  6. C# 文件类的操作---获取

    如何获取指定目录包含的文件和子目录 . DirectoryInfo.GetFiles():获取目录中(不包含子目录)的文件,返回类型为FileInfo[],支持通配符查找: . DirectoryIn ...

  7. 使用SpringMVC解决Ajax跨域问题

    package com.mengyao.system.filter; import java.io.IOException; import javax.servlet.FilterChain; imp ...

  8. elastaticsearch

    # https://elasticsearch-dsl.readthedocs.io/en/latest/ # 文档:https://es.xiaoleilu.com/054_Query_DSL/70 ...

  9. Kuangbin带你飞 AC自动机

    模板: struct Ac_Automation { int ch[MAXNNODE][SIGMA_SIZE]; int val[MAXNNODE]; int fail[MAXNNODE],last[ ...

  10. python--fnmatch

    import fnmatch ''' 这个库专门是用来做文件名匹配的,可以使用通配符如下 * 匹配任何数量的任意字符 ? 匹配单个数量的任意字符 [seq] 匹配seq中的任意字符 [!seq] 匹配 ...