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



原文地址:https://www.cnblogs.com/tuifeideyouran/p/4201033.html