Heim > Fragen und Antworten > Hauptteil
mqtt_bridge/__init__.py
# coding=utf8
from bridge import start
import threading
print 'import %s thread id: %s' % ('bridge.start', threading.current_thread().ident)
start() # 重复启动啊
在Install apps里面加入模块名,在Django启动的时候会自动导入
INSTALLED_APPS = (
# 'jet.dashboard',
# 'jet',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# Django rest framework
'rest_framework',
'rest_framework.authtoken',
# my apps
'mqtt_bridge'
)
import bridge.start thread id: 7124
bridge-54 INFO : MQTT client listen loop start! thread id: 8680
bridge-28 INFO : MQTT client connected with result code: 0
import bridge.start thread id: 8200
bridge-54 INFO : MQTT client listen loop start! thread id: 840
bridge-28 INFO : MQTT client connected with result code: 0
Performing system checks...
参考:从Django启动守护进程
伊谢尔伦2017-04-18 10:32:44
如果你想在Django的APP中执行某些初始化工作,应该在APP的app.py中自定义配置类,然后重写ready()方法即可。
Django的应用初始化过程:https://docs.djangoproject.co...