为什么django项目中的__init__模块加载了两次 [英] why is __init__ module in django project loaded twice
本文介绍了为什么django项目中的__init__模块加载了两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我把
打印'Hello world!'
$ p在我的django项目中,$ p>
into
__ init __。py
当我运行./ manage.py runserver
现在,我得到gruszczy @ gruszczy-laptop:〜/ Programy / project $ ./manage.py runserver
Hello world!
你好世界!
验证模型
0发现错误
为什么是$ $ c> __ init __。py 运行两次?只能加载一次。
解决方案每个进程只应加载一次... 。我猜,
manage.py
叉,并且启动了两个单独的进程。可以打印os.getpid()
的结果吗?I put
print 'Hello world!'
into
__init__.py
in my django project. When I run./manage.py runserver
now, I getgruszczy@gruszczy-laptop:~/Programy/project$ ./manage.py runserver Hello world! Hello world! Validating models... 0 errors found
Why is
__init__.py
run twice? It should be loaded only once.解决方案It should be loaded only once... per process. I'm guessing that
manage.py
forks, and that two separate processes are launched. Could you print the result ofos.getpid()
?这篇关于为什么django项目中的__init__模块加载了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文