python self is not defined_学习python的错误总结

1.No module named“MySQLdb”

2.NoReverseMatch at/

’url’requires a non-empty first argument.The syntax changed in Django1.5.See the docs

解决办法:路径:diango1.5版本路径需要加引号。即可解决上述问题。

例如:{% url“new_index”%}。

3.DjangoUnicodeDecodeError at/

解决办法:项目路径出现中文的问题。

4.NoReverseMatch at/

Reverse for’news_index’with arguments‘()’and keyword arguments‘{}’not found

解决办法:这种问题是没有正确的设置路径导致。这个可以先检查settings里的路径然后再检查其他子的app的路径。

5.OperationalError at/

(2003,‘Can’t connect to MySQL server on‘localhost’(10061)’)

解决办法:这个问题是因为mysql数据库没有打开。

6.TypeError at/news/

Unsupported opeaand type(s) for-:’unicode’ and ‘int’

解决办法:加了一个类型转换把unicode转换成int ;

例如:int(u’2’)。

7.ImportError: cannot import name Role

解决办法:from Manager.Role.models import Role在引用的地方查看路径是否正确。

8.NameError: name 'true' is not defined

Unhandled exception in thread started by >

Traceback (most recent call last):

File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 92, in inner_run

self.validate(display_num_errors=True)

File "C:\Python27\lib\site-packages\django\core\management\base.py", line 280, in validate

num_errors = get_validation_errors(s, app)

File "C:\Python27\lib\site-packages\django\core\management\validation.py", line 35, in get_validation_errors

for (app_name, error) in get_app_errors().items():

File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 166, in get_app_errors

self._populate()

File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 72, in _populate

self.load_app(app_name, True)

File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 96, in load_app

models = import_module('.models', app_name)

File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module

__import__(name)

File "F:\workplacepython\HBS_Photographer\Manager\News\models.py", line 10, in 

class News(models.Model):

File "F:\workplacepython\HBS_Photographer\Manager\News\models.py", line 14, in News

AddTime=models.DateTimeField(u'添加时间',auto_now_add=true)

NameError: name 'true' is not defined

解决办法:AddTime=models.DateTimeField(u'添加时间',auto_now_add=True)原因是小写的true改成大写字母True就可以了。

9.CommandError: One or more models did not validate:

CommandError: One or more models did not validate:

Photo.photo: 'FileFormat_ID' has a relation with model 图片格式id, which has either not been installed or is abstract.

Photo.photo: 'PhotoGrapherID' has a relation with model , which has either not been installed or is abstract.

Other.collect: 'Photo_ID' has a relation with model 图片ID, which has either not been installed or is abstract.

解决办法:

Q1.Photo.photo: 'FileFormat_ID' has a relation with model 图片格式id, which has either not been installed or is abstract。

A1:把FileFormat_ID=models.ForeignKey(u’文件格式ID’,FileFormat)改成FileFormat_ID=models.ForeignKey(FileFormat)。

Q2:Photo.photo: 'PhotoGrapherID' has a relation with model , which has either not been installed or is abstract.

A1:在settings里加'Manager.Photographer'。

Q3:Other.collect: 'Photo_ID' has a relation with model 图片ID, which has either not been installed or is abstract.

A3:Photo_ID=models.ForeignKey(u’图片ID’,Photo)改成Photo_ID=models.ForeignKey(Photo)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值