2011-09-19 13 views
1

djangoとchrome extensionに精通している人向けです。 djangoで作成したウェブサイトにログインすると、chrome拡張機能もログインしてアクティブになるように、どのようにしてクッキーを使用した認証を行いますか?ありがとう。クロムエクステンションとDjangoを使用した認証

答えて

1

あなたのChrome拡張機能(Javascript経由)は、Djangoアプリケーションで作成されたCookieを読み取ることができます。

Middelwareクラスを使用してCookieを設定し、JavaScript(.js Chrome拡張ファイル)で読むことができます。

Pythonコード:

class CookieMiddelware: 
    def process_request(self, request): 
     cookie = request.COOKIES.get(your_cookie_name) 
     if cookie and not request.user.is_authenticated(): 
      // authenticate user here 

クッキーを読み取るためのJavaScriptコード:

mycookie = document.cookie(your_cookie_name); 
関連する問題