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

xiaoxiao2026-05-16  13

在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 adminadmin.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 Listfrom news.article.models import Itemfrom django.contrib import adminadmin.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)
转载请注明原文地址: https://www.6miu.com/read-5048861.html

最新回复(0)