我正在使用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)
我能做什么?
我有以下代码:
问题是,当我尝试访问用户登录时/我收到错误:"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) 我想做以下事情.
我想创建一个执行以下操作的应用程序
我怎样才能以最有效的方式做到这一点?
如果餐厅给我他们的地址,我应该将该地址转换为经度/纬度点,然后以某种方式使用它来获取人的距离当前位置?但是我如何有效地这样做,以便如果数据库中有1000个地址,我可以有效地对所有这些地址进行排序 - 最接近人A的地方 - 而不需要花费太多时间?谢谢!
我正在使用django.
我有以下观点:
@api_view(POST?)
@csrf_exempt
def user_login(request):
Run Code Online (Sandbox Code Playgroud)
遵循django rest框架。
如何使该视图免除csrf?
我正在尝试通过iphone进行API调用。
我有以下代码:
- (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) 我想执行以下操作 - 允许用户在ios应用程序中输入物理地址. - 此地址转换为经度/纬度 - Django服务器代码检查以查看附近的位置.
我怎样才能最有效地完成这项工作?
我应该在ios应用程序中将地址转换为经度和纬度,然后将坐标发送到django服务器代码,还是应该将地址发送到django服务器代码然后将地址转换为经度和纬度?
任何帮助,将不胜感激!
django ×5
python ×3
cocoa-touch ×2
ios ×2
objective-c ×2
django-views ×1
geolocation ×1
ios4 ×1
ios5 ×1
iphone ×1
selector ×1