学习python的错误总结

1. No module named MySQLdb

 

 

解决办法:你没有安装MySQLdb,去安装下http://mysql-python.sourceforge.net/ 官方网站

http://sourceforge.net/projects/mysql-python/files/ 这里可以直接下到相关的文件

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 fornews_index with arguments () and keyword arguments {} not found

 

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

5. OperationalError at/

(2003,Cant 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 <bound method Command.inner_run of <django.core.management.commands.runserver.Command object at 0x02BDF870>>

Traceback (most recent call last):

  File "C:Python27libsite-packagesdjangocoremanagementcommands unserver.py", line 92, in inner_run

    self.validate(display_num_errors=True)

  File "C:Python27libsite-packagesdjangocoremanagementase.py", line 280, in validate

    num_errors = get_validation_errors(s, app)

  File "C:Python27libsite-packagesdjangocoremanagementvalidation.py", line 35, in get_validation_errors

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

  File "C:Python27libsite-packagesdjangodbmodelsloading.py", line 166, in get_app_errors

    self._populate()

  File "C:Python27libsite-packagesdjangodbmodelsloading.py", line 72, in _populate

    self.load_app(app_name, True)

  File "C:Python27libsite-packagesdjangodbmodelsloading.py", line 96, in load_app

    models = import_module('.models', app_name)

  File "C:Python27libsite-packagesdjangoutilsimportlib.py", line 35, in import_module

    __import__(name)

  File "F:workplacepythonHBS_PhotographerManagerNewsmodels.py", line 10, in <module>

    class News(models.Model):

  File "F:workplacepythonHBS_PhotographerManagerNewsmodels.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 <class 'Manager.Photographer.models.PhotoGrapher'>, 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 <class 'Manager.Photographer.models.PhotoGrapher'>, 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)

 

 

原文地址:https://www.cnblogs.com/angelfeeling/p/3392742.html