开发者

Authentication using chrome extension and Django

For those who is familiar with django and chrome extension. How do you do an authentication using cookies, such that when you login to your website made in django, your chrome extension will als开发者_运维技巧o login and become active? Thanks.


Your Chrome extension (through Javascript) can read the cookie created by your Django application.

You can set your cookies using a Middelware class and then read it in JavaScript (in your .js Chrome extension file).

Python code:

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 code for reading cookie:

mycookie = document.cookie(your_cookie_name);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜