Django source: manage.py

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mypro.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(sys.argv)
  • os.environ
    A mapping object representing the string environment.

For example, environ['HOME'] is the pathname of your home directory.

>>> import os
>>> os.environ['HOME']
'/home/alphacocoa'
  • dict.setdefault(key[, default])
    If key is in the dictionary, return its value. If not, insert key with a value of default and return default. default defaults to None.
>>> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mypro.settings")
'mypro.settings'
>>> os.environ['DJANGO_SETTINGS_MODULE']
'mypro.settings'
>>> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mypro")
'mypro.settings'              ; If key is in the dictionary, return its value.
>>> os.environ['DJANGO_SETTINGS_MODULE']
'mypro.settings'
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,959评论 0 23
  • 首先需要明确的一点儿是ECMAScript中没有event loop,event loop是在HTML Stand...
    luckySnail阅读 1,074评论 0 0
  • 检查SSH keys是否存在输入下面的命令,如果有文件id_rsa.pub 或 id_dsa.pub,则无需进入第...
    iDeaLoO阅读 227评论 0 0
  • 记得当时年纪小,你爱谈天我爱笑。小时候,笑是一件很容易的事情。看动画片,被故事情节和人物表演逗得乐不可支。和小伙伴...
    斯文韫阅读 200评论 3 2
  • 读完猫说前面一些与区块链无关的文章,我也聊一聊自己的生活。 4月中旬由于老婆待产,从无锡搬回了苏州小镇,通勤时间葱...
    陈晓东_阅读 202评论 1 3