Android的Django的用户身份验证 [英] Android-Django user authentication

查看:408
本文介绍了Android的Django的用户身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图访​​问登录的用户当前从Android应用程序在Django。
但Android应用程序意外地停止给我致命的异常。
Android的侧面code接受JSON响应,当我评论的行

I am trying to access the current logged in user from the android app in django. but the android application stops unexpectedly giving me fatal exception. the android side code accepts json response when i comment the line

在Django的身边,我有这个code,

at django side i have this code ,

@login_required 
def add_healthrecord(request):
    if request.method=='POST':
        if not request.user.is_authenticated(): # if user is not logged in
            response_data=[{"success": "0"}]
            return HttpResponse(simplejson.dumps(response_data),mimetype='application/json')
        current_user=request.User
        response_data=[{"success": "1"}]
        return HttpResponse(simplejson.dumps(response_data), mimetype='application/json')

可以请人帮助我在这里。
其实我尝试使用用户的,为什么我需要访问它的外键,多数民众赞成。
上述Django的观点给我反应,当我评论的所有用户相关的行

can please somebody help me here. actually i am trying to use user as foreign key thats why i need to access it. the above django view give me response when i comment all the user related lines

推荐答案

在没有任何详细信息,好像你不及格的CSRF令牌与您的文章命令。当使用 @login_required 装饰,你需要通过CSRF令牌(本质上是用户的会话ID)与要求,否则您将无法将数据发布到该视图。签出 Django文档更多的一些信息。

Without any more information, it seems like you're not passing the csrf token in with your post command. When using the @login_required decorator, you need to pass the csrf token (essentially the users session id) in with the request or you will not be able to post data to that view. Checkout the Django Documentation for some more info.

这篇关于Android的Django的用户身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆