django - django 承接nginx请求
2024-10-18 22:36:45
# -*- coding: utf-8 -*-
import os
import sys
import tornado.ioloop
import tornado.web
import tornado.wsgi
import tornado.httpserver
from django.core.handlers.wsgi import WSGIHandler # 设置 Django 设置模块,sets the default settings module to use
_HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.append(_HERE)
os.environ['DJANGO_SETTINGS_MODULE'] = "settings" def main(port):
# 利用 tornado 的http server处理消息请求
wsgi_app = tornado.wsgi.WSGIContainer(WSGIHandler())
# Application 处理请求消息
tornado_app = tornado.web.Application(
# FallbackHandler: A RequestHandler that wraps another HTTP server callback.
# http://www.tornadoweb.org/en/stable/web.html#tornado.web.FallbackHandler
[('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
]) # HTTPServer is a very basic connection handler. It parses the request headers and body
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(port)
tornado.ioloop.IOLoop.instance().start() if __name__ == '__main__':
try:
import setproctitle
setproctitle.setproctitle('www:' + sys.argv[1])
except ImportError:
pass
main(int(sys.argv[1]))
基本思想:利用 tornado 的 http server,处理消息请求。
官方文档有介绍:
- WSGIContainer lets you run other WSGI applications and frameworks on the Tornado HTTP server. For example, with this class you can mix Django and Tornado handlers in a single server.
详细内容,见代码注释。
最新文章
- .NET平台开源项目速览(1)SharpConfig配置文件读写组件
- 关于模拟http请求 cookie的赋值
- POI2005Bank notes银行货币
- android自动获取短信验证码
- memcached for windows 修改端口和最大内存,以及常用命令
- 为python-sproto添加map支持
- Oracle计算时间差函数
- Phython 学习笔记之——类的初步认识
- java 开发环境
- XRDP与VNC的关系
- lintcode 1: Data Stream Median
- jq的合成事件
- Ubuntu16.04 安装Tensorflow1.7过程记录二:安装CUDA及Tensorflow
- jsp中${pageContext.request.contextPath}的意思
- “教你如何玩转Web响应式布局” 的更多相关文章
- 剑指offer-矩阵覆盖
- c#语言集合分析
- 【Vue学习笔记1】全局配置 Vue.config
- memcache图形管理工具
- 形象易懂讲解算法I——小波变换
热门文章
- (转)CentOS5.5 下搭建 PHP 环境(最佳的LAMP环境)
- 为什么乱码:<;meta http-equiv=";content-type";>;前的非ANSI字符
- spring @resource @ Autowired
- linux服务器重启服务命令说明文档
- hdu 1180 诡异的楼梯(广搜,简单)
- 拼写sql语句随笔
- HDU 4143 A Simple Problem(枚举)
- hdu 1524 A Chess Game 博弈论
- java使用正则表达式——实例
- cojs 香蕉 解题报告