2014-02-13 3 views
0

나는 내 웹 사이트에 Django토네이도의 조합을 사용합니다. 토네이도는 훌륭한 인증 시스템을 가지고 있으며 장고보기에서 사용하고 싶습니다. 불행히도 AttributeError이 있습니다.django보기에서 토네이도 인증을 사용하는 방법?

어떻게 장고보기에서 토네이도 인증을 사용할 수 있습니까?

보기

import tornado.web 
from django import shortcuts 

@tornado.web.authenticated 
def testpage(request): 
    return shortcuts.render(request, 'web/templates/index.html') 

AttributeError: 'WSGIRequest' object has no attribute 'current_user' 

장고 WSGIContainer을 통해 토네이도에 연결되어있는 오류 메시지 :

def main(): 
    static_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'static') 


    assert os.path.isdir(static_path), static_path 

    wsgi_app = tornado.wsgi.WSGIContainer(
    django.core.handlers.wsgi.WSGIHandler()) 

    tornado_app = tornado.web.Application([],static_path=static_path,) 
    server = tornado.httpserver.HTTPServer(tornado_app) 

    server.listen(options.port) 
    tornado.ioloop.IOLoop.instance().start() 

if __name__ == '__main__': 
    main() 
+0

왜 당신은 장고에서 인증 된 토네이도에 대한 대안을 사용합니까? 'login_required' (소스 : https://docs.djangoproject.com/en/1.5/topics/auth/default/#the-login-required-decorator)와 같은 django 데코레이터를 사용할 수 있습니다. – scriptmonster

+0

Tornado는 Facebook, Google, Twitter 및 OAuth2 인증을 매우 간단하게 지원합니다. – Jon

답변

1

tornado.auth 모듈은 openid/oauth 플로우를 거치지 만 그 프로세스가 끝날 때까지는 쿠키를 설정 한 코드를 다시 호출합니다. get_current_user으로 토네이도의 쿠키를 읽었지 만 토네이도 RequestHandler 인터페이스에만 해당됩니다. django에서이 쿠키를 사용하려면 쿠키를 직접 읽어야합니다 (set_secure_cookie로 쿠키를 설정한다고 가정 할 때 tornado.web.decode_signed_value 함수 참조). django 프레임 워크에서 올바른 위치를 찾을 수 있습니다.이 경우 django의 login_required 데코레이터를 사용하거나 장고 핸들러에서 수행 할 수 있습니다.이 경우에는 로그인으로 리디렉션해야합니다. 직접 작성하십시오.

관련 문제