python2.6+django1.0+mysql初体验

在Windows做的,例子是照着[url]http://www.ibm.com/developerworks/cn/opensource/os-cn-django/index.html[/url]做的。
但中间因为版本问题,遇到了一些问题,特在此记录下来。
例子和我的版本比较:
python2.5 -- python 2.6
django0.96 -- django1.0

1.maxlength错误
maxlength应该改为max_length

class List(models.Model):
title = models.CharField([color=red]max_length[/color]=250,unique=True)
def __str__(self):
return self.title
class Meta:
ordering = ['title']
class Admin:
pass


2.ImportError: DLL load failed: 找不到指定的模块
MySQL的Python链接库,开始在[url]http://sourceforge.net/projects/mysql-python/[/url]没有找到适合的连接库,通过google找到文章[url]http://i.19830102.com/archives/164[/url],问题解决。

3.配置url的错误
admin后台管理界面的urls.py配置:

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Example:
# (r'^news/', include('news.foo.urls')),

# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
(r'^admin/(.*)', admin.site.root),

)


与例子讲的有所不同。

4.管理界面里,models模块显示不全,没有article模块
在文件夹articlc里,创建文件admin.py

from news.article.models import List
from news.article.models import Item
from django.contrib import admin

admin.site.register(List)
admin.site.register(Item)


5.页面显示报错

article_dict['items_complete'] = article_list.item_set.filter(completed=True).count()
article_dict['percent_complete'] = int(float(article_dict['items_complete']) / article_dict['item_count'] * 100)


这两段代码应该加上适当的判断,不然数据库没有相应的数据,会报错。

if article_dict['item_count'] == 0:
article_dict['items_complete'] = 0
article_dict['percent_complete'] = 0
else:
article_dict['items_complete'] = article_list.item_set.filter(completed=True).count()
article_dict['percent_complete'] = int(float(article_dict['items_complete']) / article_dict['item_count'] * 100)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值