python - 在Django中定义全局对象
怪我咯
怪我咯 2017-04-17 16:48:46
0
1
619
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all (1)
Ty80

That is to say, your data life cycle is the python running cycle.
In this case, you only need to separate one module (single file or multiple files).
For example,calculator.pycalculator.py
内容为:

# coding=utf-8 __all__ = ["cal1"] _g = None class _Calculate(object): def __init__(self): pass def cal1(self): # do some calculate return if _g is None: _g = _Calculate() def cal1(): return _g.cal1()

使用方式import calculatorfrom calculator import *The content is:
rrreee

Usage method import calculatoror from calculator import *can be usedNot limited to Django
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!