django book学习问题记录

——————————————————————————————————

位置:第五章《模型》

问题描述(已解决):

>>> p1 = Publisher.objects.create(name='Apress',
...     address='2855 Telegraph Avenue',
...     city='Berkeley', state_province='CA', country='U.S.A.',
...     website='http://www.apress.com/')
>>> p2 = Publisher.objects.create(name="O'Reilly",
...     address='10 Fawcett St.', city='Cambridge',
...     state_province='MA', country='U.S.A.',
...     website='http://www.oreilly.com/')
>>> publisher_list = Publisher.objects.all()
>>> publisher_list
[<Publisher: Publisher object>, <Publisher: Publisher object>] 
#当我们打印整个publisher列表时,我们没有得到想要的有用信息,无法把对象区分开来:

为mysiteooksmodules里的三个模型添加__unicode__()方法后,就可以看到效果了:

>>> from books.models import Publisher
>>> publisher_list = Publisher.objects.all()
>>> publisher_list
[<Publisher: Apress>, <Publisher: O'Reilly>]

错误:添加__unicode__()方法无效果。

解决方案:__str__():Python 3 equivalent of __unicode__().

————————————————————————————————分割线—————————————————————————————————————

                                                                            位置:第十一章:通用视图 

问题描述:django 1.5后 direct_to_template报错

from django.views.generic.simple import direct_to_template
"Could not import django.views.generic.simple.direct_to_template. Parent module django.views.generic.simple does not exist."

原因:direct_to_template() 在 django 取消了。

(’^about/$’, direct_to_template, {’template’: ’about.html’})

需要写成:

(’^about/$’, TemplateView.as_view(template_name=’about.html’))

————————————————————————————————分割线———————————————————————————————————

位置:第十一章:通用视图 

问题描述:django 1.5后 "from django.views.generic import list_detail"  报错

 原因:list_detail()在 django 取消了。

需要写成:

django.views.generic import list_detail————>django.views.generic.list.ListView

list_detail.object_detail————>ListView.as_view()

————————————————————————————————分割线———————————————————————————————————

原文地址:https://www.cnblogs.com/Simon-xm/p/3895802.html