您的位置:首页 > 运维架构 > 网站架构

网站备案不成功:备案系统的六宗~罪~ _网站备案_备案系统_网站优化

2011-08-03 22:41 471 查看
在Windows做的,例子是照着http://www.ibm.com/developerworks/cn/opensource/os-cn-django/index.html做的。
但中间因为版本问题,遇到了一些问题,特在此记录下来。
例子和我的版本比较:
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链接库,开始在http://sourceforge.net/projects/mysql-python/没有找到适合的连接库,通过google找到文章http://i.19830102.com/archives/164,问题解决。

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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: