Django 1.5 升级问题

Author Avatar
Mutse Young 3月 04, 2013

本文简述如何将 django 从1.4升级至1.5,并解答升级后遇到的问题。

安装/升级

若读者的机器没有安装 django,使用以下命令进行安装:

1
2
$ sudo apt-get install pip
$ sudo pip install Django==1.5

若已安装,则使用以下命令进行升级:

1
$ sudo pip install Django==1.5

遇到的问题

1、数据库初始化失败

1
$ python manage.py syncdb
/usr/local/lib/python2.7/dist-packages/django/conf/init.py:219: DeprecationWarning: You have no filters defined on the 'mail_admins' logging handler: adding implicit debug-false-only filter. See http://docs.djangoproject.com/en/dev/releases/1.4/#request-exceptions-are-now-always-logged DeprecationWarning)

TypeError: init() got an unexpected keyword argument 'verify_exists'

原因:model URLField 中的关键字 verify_exists 在 django 1.5 中已移除django depreciation notes for 1.5

解决方法:在 models.py 中查找 models.URLField,将其参数 verify_exists=True 删掉。

例:

1
2
3
4
5
# 修改前
some_site = models.URLField(verify_exists=True)

# 修改后
some_site = models.URLField()

2、HTML 模板解析异常

raise NoReverseMatch("'url' requires a non-empty first argument. " NoReverseMatch: 'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.

原因django 1.5 模板中 url 语法发生改变

解决方法:根据页面异常提示修改相应的模板html文件。

例:

{{post.title}}

{{post.title}}

参考资料: