-1

错误:在 /login_or_signup 中找不到 MultiValueDictKeyError 键“名称”

未提及任何行号或页面,仅提及 Django 设置文件中的页面(不是我的代码)

此 iOS 代码块失败

    //Now pass this to our login
    NSURL *url = [NSURL URLWithString:BASE_URL];
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            name, @"name",
                            email, @"email",
                            fbid, @"fbid",
                            nil];

    NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"/login_or_signup/" parameters:params];
    NSLog(@"PARAMS %@", params);
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
//do something
}failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        // your failure code here
        NSLog(@"FAILED %@", JSON);
    }]

登录或注册查看代码:

@csrf_exempt
def login_or_signup(request):

    user = False;
    username = False;
    email = "tmp@app.com"
    password = "tmppass"

    displayname = request.POST['name']
    fbid = request.POST['fbid']

    #Do we already have this user?

    if "email" in request.POST:
        email = request.POST['email']
        username = email
        try:
            user = User.objects.get(email=email)
        except User.DoesNotExist:
            pass

    if fbid and not user:
        username = fbid
        try:
            user_profile = UserProfile.objects.get(fbid=fbid)
            user = user_profile.user
        except UserProfile.DoesNotExist:
            pass

    if not user:
        user = User.objects.create_user(fbid, email, password)

    #tastypie api_key
    api = ApiKey.objects.get(user=user)

    #Update user_profile:
    user_profile = user.get_profile()
    user_profile.username = displayname
    user_profile.fbid = fbid
    user_profile.save()

    dic = list()
    dic.append({
        'username':user_profile.username, 
        'user_profile_id':user_profile.id,
        'fbid':fbid,
        'api_username':user.username,
        'api_key':api.key
    })
    return HttpResponse(simplejson.dumps(dic, cls=DjangoJSONEncoder), mimetype='application/json') 

一些方便的 iOS 代码

- (void)request:(FBRequest *)request didLoad:(id)result {

    //Loading details about this FB user.  Send the details to Web App and create and/or login this user.

    NSLog(@"FACEBOOK RESULT %@ ", result);

    NSString * fbid = [result objectForKey:@"id"];
    NSString * email = [result objectForKey:@"email"];
    NSString * name = [result objectForKey:@"name"];

    [self loginOrSignup:name email:email fbid:fbid];
}

另请注意,上面的 NSLog 确实有效,我可以看到 id、电子邮件、姓名等。

它被发送到 loginorsignup iOS 方法,该方法通过 AFNetworking 联系 url

4

1 回答 1

0

尝试在您的包含中添加引号:

urlpatterns = patterns('',    
    url(r'^admin/', include(admin.site.urls)),        
    url(r'^upload/', 'image.views.upload_file'),
    url(r'^login_or_signup', 'image.views.login_or_signup'),  
    url(r'^api/', include('v1_api.urls')) // mark the quotes
)

from django.contrib import admin如果您的 urls.py 顶部没有引号,请在 admin.site.urls 上使用引号

于 2013-02-20T22:11:26.963 回答