django写网站的时候出现的一些错误

unsupported operand type(s) for *: 'float' and 'NoneType'

在 * 这个符号不支持float和NoneType运算,多数为左右两边变量有问题(上面这个就是左边float类型,右边NoneType型无法运算)

(1062, "Duplicate entry '132' for key 'PRIMARY'") 

无法重复写入主键为132的 数据,通常是在model.py中写了super.save()方法然后又在save方法中再因为某些逻辑重新super.save()一次……也就是说

def save()内出现了两次super.save()

 

"Upload a valid image. The file you uploaded was either not an image or a corrupted image." 

这个不是异常,是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)即可 

 

UnboundLocalError at /test/shopInfo

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.

 

继续遇到继续添加 

 

 

转载于:https://www.cnblogs.com/snowleung/archive/2011/08/31/2161387.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要为 Django 网站登录界面增加密码输入错误提示功能,可以按照以下步骤进行: 1. 在 Django 项目中创建一个新的模板,用于显示密码输入错误提示。 2. 在 Django 项目中创建一个新的视图函数,用于处理登录请求,检查用户名和密码是否正确。 3. 如果密码输入错误,将错误信息传递给模板,并在模板中显示错误信息。 以下是具体的实现步骤: 1. 在 Django 项目中创建一个新的模板,例如 `login_error.html`,用于显示密码输入错误提示。在模板中添加以下内容: ```html <!DOCTYPE html> <html> <head> <title>Login Error</title> </head> <body> <h1>Login Error</h1> <p>{{ error_message }}</p> </body> </html> ``` 2. 在 Django 项目中创建一个新的视图函数,例如 `login_view`,用于处理登录请求,检查用户名和密码是否正确。在视图函数中添加以下代码: ```python from django.shortcuts import render, redirect from django.contrib.auth import authenticate, login def login_view(request): if request.method == 'POST': username = request.POST['username'] password = request.POST['password'] user = authenticate(request, username=username, password=password) if user is not None: login(request, user) return redirect('home') else: error_message = 'Invalid username or password.' return render(request, 'login_error.html', {'error_message': error_message}) else: return render(request, 'login.html') ``` 3. 如果密码输入错误,将错误信息传递给模板,并在模板中显示错误信息。在上面的代码中,如果用户认证失败,就会将错误信息传递给模板,并在模板中显示错误信息。 在 `login.html` 模板中,将登录表单的 `action` 属性设置为 `login_view` 视图函数的 URL,例如: ```html <form method="post" action="{% url 'login_view' %}"> {% csrf_token %} <label for="username">Username:</label> <input type="text" name="username" required> <br> <label for="password">Password:</label> <input type="password" name="password" required> <br> <input type="submit" value="Login"> </form> ``` 这样,当用户输入错误的密码时,就会显示密码输入错误提示页面,而不是简单地返回登录表单。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值