小编Jam*_*sen的帖子

在Django Rest Framework视图中测试身份验证 - 无法在测试时进行身份验证

在经历了这个问题的艰苦努力之后,我来寻求一些帮助.我正在为Django Rest Framework视图编写一个测试,测试我是否可以在经过身份验证时访问数据,而不是.然而,即使我通过身份验证,我仍然401 UNAUTHORIZED每次都会得到.这是我的测试:

from django.test import TestCase
from django.contrib.auth.models import User

from rest_framework.authtoken.models import Token
from rest_framework.test import APIRequestFactory, APIClient

from apps.core import models, admin
from apps.rest import views


class TestAPIViews(TestCase):
    def setUp(self):
        self.factory = APIRequestFactory()
        self.client = APIClient()
        self.user = User.objects.create_user('testuser', email='testuser@test.com', password='testing')
        self.user.save()
        token = Token.objects.create(user=self.user)
        token.save()

    def _require_login(self):
        self.client.login(username='testuser', password='testing')

    def test_ListAccounts_not_authenticated(self):
        request = self.factory.get('/accounts/')
        view = views.ListAccounts.as_view()
        response = view(request)
        self.assertEqual(response.status_code, 401,
            'Expected Response Code 401, received {0} instead.'.format(response.status_code))

    def test_ListAccounts_authenticated(self):
        self.client._require_login()
        print(self.user.is_authenticated()) …
Run Code Online (Sandbox Code Playgroud)

python django django-rest-framework

15
推荐指数
1
解决办法
7939
查看次数

django-social-auth redirect_uri无效

我一直在撞墙试图让django-social-auth工作.我的开发服务器是我工作的专用网络中的服务器,由10.0.0.*IP地址访问.我们在这台服务器上运行了多个django应用程序.这是我对这个应用程序的配置:

# Perceptual
location /perceptual/static/ {
        alias /opt/perceptual/perceptual/static/;
}
location /perceptual/ {
        proxy_pass http://127.0.0.1:8001;
}
Run Code Online (Sandbox Code Playgroud)

我正在运行我的静态目录中的backbone.js应用程序.所以,我可以去10.0.0.54/perceptual/static/,并获得我的骨干应用程序.

现在,我的设置文件中有我的Facebook APP_ID和FACEBOOK_API_SECRET,所有都已正确配置.我也有一条线在我的/ etc/hosts文件我在实际的机器(不开发服务器)指导myapp.com10.0.0.54,并为应用程序域和网站网址我的Facebook应用程序的配置是这样的:

App Domains: perceptual.com
Site URL: http://perceptual.com
Run Code Online (Sandbox Code Playgroud)

问题是,每当我去perceptual.com/perceptual/static/login/facebook/时,它都会给我这个错误: Facebook错误(django-social-auth)

下面是我的URL看起来,当我得到这个错误,如: https://www.facebook.com/dialog/oauth?scope=email&state=PC0OhXnEuaW2wcUuINO0rMSMAtVDuMbn&redirect_uri=http%3A%2F%2F127.0.0.1%3A8001%2Fperceptual%2Fcomplete% 2Ffacebook%2F%3Fredirect_state%3DPC0OhXnEuaW2wcUuINO0rMSMAtVDuMbn&CLIENT_ID = 419178148154217

所以你可以从URL看到我的redirect_uri是http://localhost:8001- 但我不希望它显然是那样.一旦我将其更改为perceptual.com,它就会更进一步:然后我收到此错误:

AuthFailed at /perceptual/complete/facebook/
Authentication failed: There was an error authenticating the app
Run Code Online (Sandbox Code Playgroud)

这是我的追溯,如果有帮助的话

在这一点上,我被困 - 我如何让我的服务器将redirect_uri更改为Facebook可以处理的东西,而不是127.0.0.1:8000?我的猜测是它来自Django,但我不知道如何改变它.然后,一旦修复,它仍然无法完全验证,并得到上述错误.任何帮助将不胜感激.非常感谢!

python django django-socialauth

6
推荐指数
1
解决办法
2230
查看次数

无法在UIBarButtonItem上设置操作

所以我在UIToolbar中添加了一堆自定义UIBarButtonItems,它们都加载得很好,看起来很棒,我可以在UIToolbar中看到它们.唯一的问题是,我无法对它们执行任何操作.在我的viewDidLoad中,我设置了所有内容.这是我的.h和.m文件:

.h文件:

#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <QuartzCore/QuartzCore.h>

@interface PhotoEditViewController : UIViewController <UIPopoverControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIGestureRecognizerDelegate> {
    IBOutlet UIImageView *imageView; 
}

- (IBAction)cancelEdit:(id)sender;
- (IBAction)savePhoto:(id)sender;
- (IBAction)chooseColor:(id)sender;


@property (retain) IBOutlet UIToolbar *editBar;
@property (retain) UIImageView *imageView;
@property (retain) UIImage *tempImage;

- (void) setupStache;

@end
Run Code Online (Sandbox Code Playgroud)

.m文件:(viewDidLoad)

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.imageView.image = tempImage;


    NSMutableArray *toolbarItems = [NSMutableArray arrayWithCapacity:3];

    // get the filepaths of all the images
    NSString *imagePath_cancel = [[NSBundle mainBundle] pathForResource:@"barBtnPhotoEditCancel" ofType:@"png"];
    NSString *imagePath_save …
Run Code Online (Sandbox Code Playgroud)

iphone xcode uibarbuttonitem ios

1
推荐指数
1
解决办法
3359
查看次数