zoukankan      html  css  js  c++  java
  • django最佳实践

    导入的时候使用绝对导入或者清晰的相对导入

    相对导入用法:

    from __future__ import absolute_import
    from .models import what_u_need
    而不是
    form model import what_u_nedd
    

     在python 2.x中也使字符串采用3.x编码

    from __future__ import unicode_literals
    

     INTERNAL_IPS:一个元组,里面的每一项都是一个IP地址,和DEBUG联合使用,可以设置某台设备上是否可以显示错误信息.

    涉及到数据库交互的可以使用

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
            'ATOMIC_REQUESTS': True,
        }
    }

    其中ATOMIC_REQUESTS,注意:

    这个最好不要用于django.http.streamingHttpResponse

    Therefore, when writing views that create/update/delete records but interact with non-database items, you may choose
    to decorate the view with transaction.non_atomic_requests()


    
    
  • 相关阅读:
    二维数组中的查找
    循环语句
    掷骰子游戏和条件语句
    类型转换与键盘输入
    运算符(2)
    运算符(1)
    面向对象(2)
    面向对象(1)
    理解几种排序方法
    优盘、移动硬盘简便制作启动盘
  • 原文地址:https://www.cnblogs.com/tuifeideyouran/p/4201033.html
Copyright © 2011-2022 走看看