Using django model/authentication/authorization within Tornado
There is a project which is deployed within django. So its authentication system is built from Django itself.
But ususually we want to get good use of it. And we don't want to build another system to manage 'user' information.
So, we can use django within tornado. I mean use tornado more.
We can build an service application using tornado.
For example, there is a file for tornado which would look like this:
It's a hello world tornado app. save it as tornado_service.py
___________________
Hello, world
Here is a simple “Hello, world” example web app for Tornado:
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world") application = tornado.web.Application([
(r"/", MainHandler),
]) if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
This example does not use any of Tornado’s asynchronous features; for that see this simple chat room.
___________________
Make django work within tornado
import tornado.ioloop
import tornado.web
import os
# the settings refers to a file settings.py (it's the django main project's settings.py )
# just add the route in the os.environ[]
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
# now you can use the authenticate lib from django
# the settings could include many setting details such as 'database', 'path', and etc..
from django.contrib.auth import authenticate class MainHandler(tornado.web.RequestHandler):
def get(self):
username = self.get_argument("username")
password = self.get_argument("password")
user = authenticate(username= username, password = password)
if user:
self.write("hello " + user.username)
else:
self.write("Wrong username or password! :(" )
return application = tornado.web.Application([
(r"/", MainHandler),
]) if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
then run this tornado app:
$ python tornado_service.py
In your web browser,
go to http://127.0.0.1:8888/?username=jake&password=anderson
If the password matches, then you will get
hello jake
If doesn't, then
Wrong username or password! :(
Now you can make django work within torando.
Have fun! Happy hacking!
Using django model/authentication/authorization within Tornado的更多相关文章
- tornado with MySQL, torndb, django model, SQLAlchemy ==> JSON dumped
现在,我们用torndo做web开发框架,用他内部机制来处理HTTP请求.传说中的非阻塞式服务. 整来整去,可谓之一波三折.可是,无论怎么样,算是被我做成功了. 在tornado服务上,采用三种数据库 ...
- 【转】Django Model field reference学习总结
Django Model field reference学习总结(一) 本文档包含所有字段选项(field options)的内部细节和Django已经提供的field types. Field 选项 ...
- Django model字段类型清单
转载:<Django model字段类型清单> Django 通过 models 实现数据库的创建.修改.删除等操作,本文为模型中一般常用的类型的清单,便于查询和使用: AutoField ...
- Django:Model的Filter
转自:http://www.douban.com/note/301166150/ django model filter 条件过滤,及多表连接查询.反向查询,某字段的distinct 1.多表 ...
- Django model中 双向关联问题,求帮助
Django model中 双向关联问题,求帮助 - 开源中国社区 Django model中 双向关联问题,求帮助
- django 自定用户系统 以及 Django Model 定义语法
http://www.tuicool.com/articles/jMzIr2 django使用自己的用户系统 http://www.jianshu.com/p/c10be59aad7a Django ...
- Django Model field reference
===================== Model field reference ===================== .. module:: django.db.models.field ...
- Django model对象接口
Django model查询 # 直接获取表对应字段的值,列表嵌元组形式返回 Entry.objects.values_list('id', 'headline') #<QuerySet [(1 ...
- Django学习之四:Django Model模块
目录 Django Model 模型 MODEL需要在脑子里记住的基础概念 区分清楚,必须不能混淆的 class Meta 内嵌元数据定义类 简单model创建实例 数据源配置 接着通过models在 ...
随机推荐
- A generic error occurred in GDI+. 上传图片报错
代码就不说了,因为本地测试 ok, 服务端 就不行 ,服务器 环境 阿里云 win2008 r2 64 位 原因 是我没有这是 文件加权限 : 左边 的 少了 权限~ 代码 :含义是 网络图片 裁剪 ...
- IBM BigInsights 3.0.0.2 集群环境搭建
1. 改动hosts文件和永久主机名 由于BigInsights 3.0版本号不像之前的版本号能够直接用IP来添加节点,因此我们须要更改每台server的hosts文件和主机名: vim/etc/ho ...
- 有空就写个C++程序
近期工作变得轻松了非常多,有了一些空暇的时间,准备把大学时候的C++抓起来,而且研究研究算法: 第一个C++程序:计算圆的面积,也是看其它的博客写出来的C++程序. #include<iostr ...
- IOS开发中怎样验证邮箱的合法性
IOS开发中怎样验证邮箱的合法性 文章参考:http://www.codes51.com/article/detail_94157.html 代码: - (void)viewDidLoad { [su ...
- 高速决心linux上oracle安装垃圾问题
问题:在linux安装oracle时间.因为oracle用户local LANG安装问题,原因安装oracle软件.该接口是非常多的安装位置是乱码. 解决方案:在oracle用户运行:export L ...
- android简单的计算器
所使用的算法:表达式求值(中缀表达式转后缀表达式,后缀表达式求值值) 不如何设计接口,有时间来美化! MainActivity.java package com.example.calculator; ...
- PhpStorm创建Drupal模块项目开发教程
在PhpStorm开发工具中,创建Drupal开发项目有两种方式:整合Drupal到现有的项目中和直接创建一个新的Drupal模块. 接下来将展示这两种方式的具体操作! 整合Drupal到现有的项目 ...
- Git 和 Github的关系
惭愧,这个问题到昨天才弄明白! Git 其实是一种版本控制的协议,和SVN/CVS类似,git协议定义了一个版本控制相关的各个操作,和SVN/CVS不同的是,git采用的是分布式的方法,并不需要服务器 ...
- Bootstrap面包屑导航
Bootstrap中提供了面包屑导航的实现方法: 只需要引入bootstrap.css文件即可. 主要引用的样式有: .span6 .breadcrumb 实例代码如下: <!DOCTYPE h ...
- Linux 宿主机安装 MiniGUI
去MiniGUI官方网站看的时候,很兴奋,安装竟然这么容易. 上帝总是在给你一个苹果之后,赏你一巴掌.我的确是高兴太早了. 首先看一下官网文档的说明步骤: (截取于官方文档) Installing r ...