推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
halicando
V2EX  ›  Python

实际应用 django 时发现,有的版本,在 同一个 app 下,views 中无需 import 就能直接使用 model 类。官方文档里有这一说?

  •  
  •   halicando · Jun 26, 2013 · 4308 views
    This topic created in 4881 days ago, the information mentioned may be changed or developed.
    7 replies  •  1970-01-01 08:00:00 +08:00
    mutoulbj
    mutoulbj
    Jun 26, 2013
    1
    有吗?
    qdvictory
    qdvictory
    Jun 26, 2013
    2
    有可能是间接引用了吧
    halicando
    halicando
    OP
    Jun 26, 2013
    3
    @qdvictory 比如呢?
    walnutist
    walnutist
    Jul 9, 2013
    4
    x.py

    from some.package import TheBadAssClass

    y.py

    from x import *

    print dir(TheBadAssClass)

    除非在x.__all__中显示定义不暴露TheBadAssClass出来,否则从x中import *,会把TheBadAssClass带进来的
    qdcanyun
    qdcanyun
    Jul 9, 2013
    5
    能否举个例子。。。。
    如果4楼说的情况 感觉尽量别这么用 还是独立的写一条from...import...吧 不然就会产生依赖关系 以后如果有了bug可能会有什么影响。。。。
    buru
    buru
    PRO
    Jul 9, 2013
    6
    4楼正解
    个人感觉独立写一条import比较好
    siteshen
    siteshen
    Jul 11, 2013
    7
    和 django 没啥关系。

    from X import * imports the module X, and creates references in the current namespace to all public objects defined by that module (that is, everything that doesn’t have a name starting with “_”).
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1782 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 15:53 · PVG 23:53 · LAX 07:53 · JFK 10:53
    ♥ Do have faith in what you're doing.