小编use*_*822的帖子

Django REST框架CSRF失败:未设置CSRF cookie

我正在使用django rest框架通过IOS执行API调用,我收到以下错误"CSRF失败:未设置CSRF cookie".

这是我的django API代码:

class LoginView(APIView):
    """
    List all snippets, or create a new snippet.
    """
    @csrf_exempt
    def get(self, request, format=None):
        startups = Startup.objects.all()
        serializer = StartupSerializer(startups, many=True)
        return Response(serializer.data)

    @csrf_exempt
    def post(self, request, format=None):
        profile = request.POST
....
Run Code Online (Sandbox Code Playgroud)

我能做什么?

python django django-views django-rest-framework

20
推荐指数
4
解决办法
2万
查看次数

CSRF豁免失败 - APIView csrf django休息框架

我有以下代码:

问题是,当我尝试访问用户登录时/我收到错误:"CSRF失败:未设置CSRF cookie."

我能做什么?

我正在使用django rest框架.

urls.py:

url(r'^user-login/$', 
    csrf_exempt(LoginView.as_view()),
    name='user-login'),

views.py:

class LoginView(APIView):
"""
List all snippets, or create a new snippet.
"""
def get(self, request, format=None):
    startups = Startup.objects.all()
    serializer = StartupSerializer(startups, many=True)
    return Response(serializer.data)

def post(self, request, format=None):
    profile = request.POST

    if ('user_name' not in profile or 'email_address' not in profile or 'oauth_secret' not in profile):
        return Response(
            {'error': 'No data'},
            status=status.HTTP_400_BAD_REQUEST)

    username = 'l' + profile['user_name']
    email_address = profile['email_address']
    oauth_secret = profile['oauth_secret']
    password = oauth_secret
Run Code Online (Sandbox Code Playgroud)

python django django-rest-framework

8
推荐指数
2
解决办法
7736
查看次数

如何使用Django进行有效的地理定位?

我想做以下事情.

我想创建一个执行以下操作的应用程序

  • 餐馆放在他们所在的地址.
  • 人员A打开应用程序并查看每个餐馆距离他/她当前位置的里程数,按最近排序.

我怎样才能以最有效的方式做到这一点?

如果餐厅给我他们的地址,我应该将该地址转换为经度/纬度点,然后以某种方式使用它来获取人的距离当前位置?但是我如何有效地这样做,以便如果数据库中有1000个地址,我可以有效地对所有这些地址进行排序 - 最接近人A的地方 - 而不需要花费太多时间?谢谢!

我正在使用django.

python iphone django geolocation

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

Hercules:csrf豁免django rest框架

我有以下观点:

@api_view(POST?)
@csrf_exempt
def user_login(request):
Run Code Online (Sandbox Code Playgroud)

遵循django rest框架。

如何使该视图免除csrf?

我正在尝试通过iphone进行API调用。

django django-rest-framework

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

UIButton动作选择器

我有以下代码:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {



    UIImage * search = [UIImage imageNamed: @"search.png"];
    UIImageView * s = [[UIImageView alloc] initWithImage: search];
    s.frame = CGRectMake(15, 14, search.size.width, search.size.height);

    UIImage * simg = [UIImage imageNamed: @"m_search_back.png"];
    UIImage * img = [UIImage imageNamed: @"m_top.png"];
    CGRect searchBarFrame = CGRectMake(0, 0, self.tableView.frame.size.width, 45.0);
    self.searchBar = [[UISearchBar alloc] initWithFrame:searchBarFrame];
    self.searchBar.backgroundImage = simg;
    [self.searchBar setSearchFieldBackgroundImage: simg forState:UIControlStateNormal];
    self.searchBar.delegate = self;
    [self.searchBar addSubview: s];


    UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];

    // Change search bar text color
    searchField.textColor = …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c selector ios4 ios

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

将地址转换为经度和纬度

我想执行以下操作 - 允许用户在ios应用程序中输入物理地址. - 此地址转换为经度/纬度 - Django服务器代码检查以查看附近的位置.

我怎样才能最有效地完成这项工作?

我应该在ios应用程序中将地址转换为经度和纬度,然后将坐标发送到django服务器代码,还是应该将地址发送到django服务器代码然后将地址转换为经度和纬度?

任何帮助,将不胜感激!

django cocoa-touch objective-c ios ios5

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