老师,还有另外一个问题。
如果我想在django中运行TCP Server,该服务用来接收客户端相关信息,然后通过web http的轮询来返回给前端。那么,在哪里启动该服务比较好呢,是在manage.py中启动新进程来执行嘛?类似于下面这种:
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mat_server.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
# 启动TCP Server
start_tcp_server()
execute_from_command_line(sys.argv)
Django REST framework课程视频,RESTFul API前后端分离开发
了解课程