Django 1.4部署和os.environ.setdefault

时间:2021-06-22 22:47:56

In the new Django 1.4 project layout, I have a declaration of os.environ.setdefault on manage.py and wsgi.py inside the project folder. What is the difference between the two?

在新的Django 1.4项目布局中,我在项目文件夹中的manage.py和wsgi.py上声明了os.environ.setdefault。两者有什么区别?

Also, if I have this settings structure:

另外,如果我有这个设置结构:

mysite
|-- mysite
|   |-- settings
|   |-- base.py
|   |-- dev.py
|   |-- production.py
|   wsgi.py
|-- myapp
|-- manage.py

which os.environ.setdefault should I edit? The one in manage.py or the one in wsgi.py?

我应该编辑哪个os.environ.setdefault? manage.py中的那个或wsgi.py中的那个?

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

also, in which file should I detect the current env? and how do I do so?

另外,我应该在哪个文件中检测当前的env?我该怎么办?

1 个解决方案

#1


1  

So manage.py is never executed once deployed, its mainly for development and/or executing commands against your project so its the wsgi.py that you're interested in.

因此,manage.py一旦部署就永远不会被执行,它主要用于开发和/或执行针对您项目的命令,因此它是您感兴趣的wsgi.py。

You can check this by looking at the file itself which has: if __name__ == "__main__": that should tell you that the file is meant to be executed directly from command line.

您可以通过查看具有以下内容的文件本身来检查:if __name__ ==“__ main __”:这应该告诉您该文件是直接从命令行执行的。

#1


1  

So manage.py is never executed once deployed, its mainly for development and/or executing commands against your project so its the wsgi.py that you're interested in.

因此,manage.py一旦部署就永远不会被执行,它主要用于开发和/或执行针对您项目的命令,因此它是您感兴趣的wsgi.py。

You can check this by looking at the file itself which has: if __name__ == "__main__": that should tell you that the file is meant to be executed directly from command line.

您可以通过查看具有以下内容的文件本身来检查:if __name__ ==“__ main __”:这应该告诉您该文件是直接从命令行执行的。