django写网站的时候出现的一些错误
在 * 这个符号不支持float和NoneType运算,多数为左右两边变量有问题(上面这个就是左边float类型,右边NoneType型无法运算)
(1062, "Duplicate entry '132' for key 'PRIMARY'")
无法重复写入主键为132的 数据,通常是在model.py中写了super.save()方法然后又在save方法中再因为某些逻辑重新super.save()一次……也就是说
def save()内出现了两次super.save()
这个不是异常,是form的提示,对应中文为:您所上传的文件不是图片或者是已损坏的图片
正确的上传图片都会出现这个,网上的解决方案为install libjpeg libjepg-dev,试过,无效!
后来我换了一个python版本,行了,出现这个问题时用的是python2.5
后来用python2.6就没有这个问题了!
ModelForm has no model class specified.
在继承了ModelForm的Form中没有加上
class Meta:
model=你的model
TypeError: super() argument 1 must be type, not classobj
通常是因为old class 引起的。在基类上写上
class baseclass(object)即可
local variable 'obj' referenced before assignment
未绑定的本地错误。
本地变量 obj 在指派前被引用。
通常就是未在上文声明obj变量,但是却在在下文引用了
如以下逻辑
if None:
obj=111
else :
print obj;//出错。
错误'IOError: sys.stdout access restricted by mod_wsgi'
l
A: A portable WSGI application or application component should not output anything to standard output. This is because some WSGI hosting mechanisms use standard output to communicate with the web server. If a WSGI application outputs anything to standard output it will thus potentially interleave with the response sent back to the client.To promote portability of WSGI applications, mod_wsgi by default restricts direct use of 'sys.stdout' and 'sys.stdin'. Because the 'print' statement defaults to outputing text to 'sys.stdout', using 'print' for debugging purposes can cause this error.
意思就是项目中不能出现print打印语句,需要删除
The 'avatar' attribute has no file associated with it.
原型是这样的: raise ValueError("The '%s' attribute has no file associated with
it." % self.field.name)
avatar属性 没有相关的文件。
意思就是avatar这个属性,没有上传文件。
通常发生在,model中的imagefield字段没有设定为blank=True,不可空的属性必须赋值才能写入数据库,否则出错
UnicodeEncodeError: 'ascii' codec can't encode characters in position 70-74: ordinal not in range(128)
这个问题极度恶心,如果不是运气好,还真没有办法解决。http://stackoverflow.com/questions/4398540/unicodeencodeerror-when-saving-imagefield-containing-non-ascii-characters-in-dja/8342356#8342356
https://docs.djangoproject.com/en/dev/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror
n linux:
echo $LANG i got zh_CN.UTF-8
in apache2/envvars
export LANG='zh_CN.UTF-8' #keep this variable like echo $LANG.
export LC_ALL='zh_CN.UTF-8' #the same.
继续遇到继续添加
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?