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的更多相关文章

  1. tornado with MySQL, torndb, django model, SQLAlchemy ==> JSON dumped

    现在,我们用torndo做web开发框架,用他内部机制来处理HTTP请求.传说中的非阻塞式服务. 整来整去,可谓之一波三折.可是,无论怎么样,算是被我做成功了. 在tornado服务上,采用三种数据库 ...

  2. 【转】Django Model field reference学习总结

    Django Model field reference学习总结(一) 本文档包含所有字段选项(field options)的内部细节和Django已经提供的field types. Field 选项 ...

  3. Django model字段类型清单

    转载:<Django model字段类型清单> Django 通过 models 实现数据库的创建.修改.删除等操作,本文为模型中一般常用的类型的清单,便于查询和使用: AutoField ...

  4. Django:Model的Filter

    转自:http://www.douban.com/note/301166150/   django model filter 条件过滤,及多表连接查询.反向查询,某字段的distinct   1.多表 ...

  5. Django model中 双向关联问题,求帮助

    Django model中 双向关联问题,求帮助 - 开源中国社区 Django model中 双向关联问题,求帮助

  6. django 自定用户系统 以及 Django Model 定义语法

    http://www.tuicool.com/articles/jMzIr2 django使用自己的用户系统 http://www.jianshu.com/p/c10be59aad7a Django ...

  7. Django Model field reference

    ===================== Model field reference ===================== .. module:: django.db.models.field ...

  8. Django model对象接口

    Django model查询 # 直接获取表对应字段的值,列表嵌元组形式返回 Entry.objects.values_list('id', 'headline') #<QuerySet [(1 ...

  9. Django学习之四:Django Model模块

    目录 Django Model 模型 MODEL需要在脑子里记住的基础概念 区分清楚,必须不能混淆的 class Meta 内嵌元数据定义类 简单model创建实例 数据源配置 接着通过models在 ...

随机推荐

  1. jquery.validate 验证(支持前台js验证通过,然后ajax后台数据校验)二

      jquery.validate  为啥 源码 里面 规定 dataType: "json" 呢 因为 他配套的 是  messages  下面 的 remote  属性 验证失 ...

  2. (转)迎接 Entity Framework 7

    对实体框架的下一版本的开发正在顺利进行中.我在 2014 年度北美 TechEd 上第一次了解 EF 团队的工作内容,当时项目经理 Rowan Miller 讨论了 Entity Framework ...

  3. addEventListener

    addEventListener addEventListener-开始 前面零散地写了些关于 addEventListener 的内容,觉得比较散,有些地方可能也说得不够清楚明白,所以决定以连载的形 ...

  4. 一步一步写算法(之n!中末尾零的个数统计)

    原文:一步一步写算法(之n!中末尾零的个数统计) [ 声明:版权所有,欢迎转载,请勿用于商业用途.  联系信箱:feixiaoxing @163.com] 在很多面试的题目中,求n!结果中零的个数也是 ...

  5. web浏览器中javascript

    1.异步载入一个js代码function loadasync(url) { var head = document.getElementsByTagName("head")[0]; ...

  6. ajax 请求数据

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  7. t_sql语句得到表中所有信息

    --得到所有数据库SELECT Name FROM Master..SysDatabases ORDER BY Name --得到某一数据库的所有表SELECT Name FROM MyPhotos. ...

  8. ext日期加减任意天数

    1.Ext.util.Format.date(new Date().add(Date.DAY, 5), 'Y-m-d'), 'Y-m-d') 2.Ext.util.Format.date(new Da ...

  9. ASP.NET MVC显示WebForm网页或UserControl控件

    ASP.NET MVC显示WebForm网页或UserControl控件 学习与使用ASP.NET MVC这样久,还是对asp.net念念不忘.能否在asp.net mvc去显示aspx或是user ...

  10. Effective C++(12) 复制对象时要复制每一个成员

    问题聚焦: 负责拷贝的两个操作:拷贝构造函数和重载赋值操作符. 一句话总结,确保被拷贝对象的所有成员变量都做一份拷贝. Demo   void logCall(const std::string&am ...