django.conf.settings和导入设置之间有什么区别吗? [英] Is there any difference between django.conf.settings and import settings?

查看:34
本文介绍了django.conf.settings和导入设置之间有什么区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django应用中,以下import语句之间的基本区别是什么?

What is the basic difference between the following import statements in a Django app?

import settings

from django.conf import settings

推荐答案

import settings

将导入Django项目的settings..py模块(当然,如果您是从应用程序的"root"包中编写此代码的话)

Will import settings(.py) module of your Django project (if you are writing this code from the "root" package of your application, of course)

from django.conf import settings

将从django.conf包(Django提供的文件)中导入设置 object .这很重要,因为

Will import settings object from django.conf package (Django's provided files). This is important, because

[..]请注意,您的代码不应从global_settings或您自己的设置文件中导入.django.conf.settings抽象了默认设置和特定于站点的设置的概念;它提供了一个单一的界面.还将使用设置的代码与设置的位置分离.

[..] note that your code should not import from either global_settings or your own settings file. django.conf.settings abstracts the concepts of default settings and site-specific settings; it presents a single interface. It also decouples the code that uses settings from the location of your settings.

更新:如果要定义一些自己的设置,请参见这部分内容文档

UPDATE: if you want to define some own settings, see this part of the documentation

这篇关于django.conf.settings和导入设置之间有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆