使用Tornado作为Django App的服务器
来源:互联网 发布:电脑测试性能软件 编辑:程序博客网 时间:2024/05/22 14:24
闲来无事,折腾折腾。
老是听说tonado是个异步web框架和服务器,作为框架倒是了解到了,但是服务器一直不太懂。所以决定了解一下,既然可以做服务器,那就把自己的django app部署到这上边去。
先是*Google*了一下,找到了一篇相关[博客](https://thinkfaster.co/2015/01/run-django-on-tornado/)。于是乎,将其改造改造,直接搬过来。原作是要用*websocket*这个东东,而我只是要App部署上去就OK。发现需要的代码是相当精简的。
import osos.environ.setdefault("DJANGO_SETTINGS_MODULE", "myblog.settings")import django.confimport django.contrib.authimport django.core.handlers.wsgifrom django.core.wsgi import get_wsgi_applicationimport django.dbimport tornado.httpserverimport tornado.ioloopimport tornado.webimport tornado.wsgifrom tornado.options import options, definedefine('port', type=int, default=8080)class HelloHandler(tornado.web.RequestHandler): def get(self): self.write('Hello from tornado')def main(): wsgi_app = tornado.wsgi.WSGIContainer(get_wsgi_application()) tornado_app = tornado.web.Application( [ (r'/hello-tornado*', HelloHandler), (r'.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)), ]) server = tornado.httpserver.HTTPServer(tornado_app) server.listen(options.port, address='192.168.1.59') tornado.ioloop.IOLoop.instance().start()if __name__ == '__main__': main()
有一些改动,在WSGIContainer中,原作使用的是:
wsgi_app = tornado.wsgi.WSGIContainer( django.core.handlers.wsgi.WSGIHandler())
然后自己用就报错了The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don’t make non-lazy gettext calls at import time我勒个去。
最后发现得用
from django.core.wsgi import get_wsgi_application
用get_wsgi_application替代。
哈哈,OK,python tonado_main.py就把他给跑起来了。
0 0
- 使用Tornado作为Django App的服务器
- ngnix 作为django项目的web服务器
- 使用Tornado+Nginx部署Django的一种尝试
- Django和Tornado 的理解
- 使用 CherryPy 作为Django的Development Server
- 使用 CherryPy 作为Django的Development Server
- 安装apache作为django服务器
- django app服务器搭建
- Tornado服务器环境的安装
- tornado----编写简易的服务器
- tornado的简单使用
- 自己写一个 wsgi 服务器运行 Django 、Tornado 应用
- Python Django的使用:Writing your first Django app--实践
- 在生产系统使用Tornado WebServer来代替FastCGI加速你的Django应用
- 在生产系统使用Tornado WebServer来代替FastCGI加速你的Django应用
- Linux上使用MSSQL Server作为Django的Database Backend
- Redis作为MySQL缓存服务器的使用
- 关于TORNADO的使用(转帖)
- hive中内部表和外部表
- PHP7新特性整理介绍篇
- LinuxCNC+EtherCAT(4)之LinuxCNC overview
- JSP内置对象
- 【Space Shoot Project】Adding a background
- 使用Tornado作为Django App的服务器
- linux下通过lseek()实现文件大小设置
- SAP中会计凭证和物料凭证的对应关系
- 面试题23:从上往下打印二叉树
- 为什么用fopen打开远程URL会很慢?
- 一个小程序看流的读取
- android的EditText,焦点会默认在第一个EditText中,我不希望焦点默认在任何EditText中,如何做?
- Linux OS下分区的擦除与重写
- 九度oj 题目1443:Tr A