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()

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

  • 相关阅读:
    海康视频 rtnp转 flv
    生成随机不重复数列表(C#)
    保证应用程序只运行一个实例[c#]
    [C++] C++指针的那些事 常量,变量,指针及指针相关的三个数值
    C#压缩与解压缩流类 GZipStream 的使用
    [C# WinFrom 使用 Google Map] 在地图上画轨迹线
    一个泛型应用示例
    没五笔,不写了
    利用Socket HTTP协议获得HTML代码方法
    Remoting实例(客户端发送信息)
  • 原文地址:https://www.cnblogs.com/Simon-xm/p/3895802.html
Copyright © 2011-2022 走看看