原文链接:http://www.vpsee.com/2009/07/update-examples-in-django-step-by-step/#comments
周末看了 limodou 的 Django Step by Step 入门教程,写得很棒,通俗易懂,谢谢先。Django 发展太快,现在已是 1.0.2 版本,可惜 Django Step by Step 上面的例子还是 0.9x 版本,所以编译运行上面的例子时会出现一些问题,主要是一些兼容问题,列出来以供参考:

第六讲

3、编辑 wiki/models.py


pagename = models.CharField(maxlength=20, unique=True)

在 Django 1.0.2 中,上面的 maxlength 应改为:

max_length
6、修改 wiki/views.py


c = Context({‘pagename’:page.pagename, ‘content’:content})

上面代码输出 content 时会把 “< >” 等字符转义输出成 “< &gt”,这个时候需要关闭自动转义,以便 content 输出 HTML 代码。改成如下: c = Context({'pagename':page.pagename,'content':content},autoescape=False) 还有一种方法就是在 wiki/page.html 里改成: {% autoescape off %} {{ content }} {% endautoescape %} 第七讲 3、修改 address/models.py … gender = models.CharField(‘性别’, choices=((‘M’, ‘男’), (‘F’, ‘女’)), maxlength=1, radio_admin=True) … 注意上面的 radio_admin=True 已经在 Django 1.0.2 中不适用了,不能写在 field 里,admin 和 model分离了,把 models.py 的全部内容用以下代码替换: from django.db import models # Create your models here. class Address(models.Model): name = models.CharField('Name', max_length=6, unique=True) gender = models.CharField('Sex', choices=(('M', 'Male'), ('F', 'Female')), max_length=1) telphone = models.CharField('Telphone', max_length=20) mobile = models.CharField('Cellphone', max_length=11) room = models.CharField('Room', max_length=10) from django.contrib import admin class AddressAdmin(admin.ModelAdmin): model=Address radio_fields = {'gender':admin.VERTICAL} admin.site.register(Address, AddressAdmin) 6、修改 urls.py from django.conf.urls.defaults import * urlpatterns = patterns(”, … # Uncomment this for admin: (r’^admin/’, include(‘django.contrib.admin.urls’)), ) 新的变化已经在 Django 1.0.2 生成的默认 url.py 里了,只需要把 urls.py 里面的 comment 前面的 # 去掉就可以了。 # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() # Uncomment the next line to enable the admin: (r'^admin/(.*)', admin.site.root), 7、增加超级用户 manage.py shell >>> from django.contrib.auth.create_superuser import createsuperuser
>>> createsuperuser()

只需要改成下面一条命令:

./manage.py createsuperuser
以上修正在 Django 1.0.2 + Python 2.5.1 + Mac OS X 10.5.7 上调试通过。