zoukankan      html  css  js  c++  java
  • 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()

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

  • 相关阅读:
    BZOJ 1266: [AHOI2006]上学路线route
    重磅!阿里云Promtheus 正式免费公测
    解锁云原生 AI 技能|在 Kubernetes 上构建机器学习系统
    更新与发展 | Alibaba Cloud Linux 2 特性与开发细节揭秘
    《2019上半年DDoS攻击态势报告》发布:应用层攻击形势依然严峻,海量移动设备成新一代肉鸡
    《2019年上半年Web应用安全报告》发布:90%以上攻击流量来源于扫描器,IP身份不再可信
    并发模式与 RPS 模式之争,性能压测领域的星球大战
    互联网商城的上云改造之旅
    技术人具备“结构化思维”意味着什么?
    弘康人寿基于 RocketMQ 构建微服务边界总线的实践
  • 原文地址:https://www.cnblogs.com/Simon-xm/p/3895802.html
Copyright © 2011-2022 走看看