Loading

Django - 脚本调用Django环境

目录

    如何在脚本中调用Django环境:

    import os
    import django
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MB.settings")  # MB:项目名称
    django.setup()
    
    from app01 import models
    
    def foo():
        api_obj = models.API.objects.all()
        for i in api_obj:
            print(i.api_stop_time)
    
    if __name__ == '__main__':
        foo()
    

    see also:https://www.cnblogs.com/maple-shaw/articles/9403501.html

    posted @ 2020-01-06 17:16  听雨危楼  阅读(238)  评论(0编辑  收藏  举报