python - django-tastypie simple GET gives 400 error -


i'm using python2.7, django1.6, , apache2. have enabled crossdomain access. have tried , without crsf token. have no idea i'm doing wrong.

visiting: url/to/site/contacts/api/v1/adresponses/1 works tastypie set up. can see ad responses.

someone please help. have been stuck trying tastypie work days now.

here api.py

class userresource(modelresource):     class meta:             queryset = user.objects.all()             resource_name = 'user'             fields=['username', 'id']             allowed_methods = ['get']             authorization = authorization()             authentication = authentication()   class adresponsesresource(modelresource):     users = fields.manytomanyfield('contacts.api.userresource', 'users',                     related_name='adresponse')     class meta:             queryset = adresponses.objects.all()             resource_name = 'adresponses'             authorization = authorization()             authentication = authentication() 

this ajax call

$(function (){     $.ajax({         url: 'url/to/site/contacts/api/v1/adresponses/1',         type: 'get',         accepts: 'application/json',         datatype: 'json'     }); 

so i'm not entirely sure why original posted js doesn't work saw example http://django-tastypie.readthedocs.org/en/latest/cookbook.html , works expect. maybe because didn't have success function?

$.ajax({     url: '../../api/v1/user/',     contenttype: 'application/json',     type: 'get',      success: function(data, textstatus, jqxhr) {          // processing of data here.          console.log(data);          }     }); 

i need see url set api give more help, starters original url provided:

url: 'url/to/site/contacts/api/v1/adresponses/1', 

and 1 in answer

url: '../../api/v1/user/', 

do not call same resource makes harder diagnose.

however, first url absolute path , second relative causing issues allowed_hosts setting generating 400 error.

so try this:

 $.ajax({     url: '../../api/v1/adresponses/1',     contenttype: 'application/json',     type: 'get',      success: function(data, textstatus, jqxhr) {          console.log(data);          }     }); 

yes, without success function not see results:

success: function(data, textstatus, jqxhr) {     console.log(data); } 

that console.log makes see result in console.

your origanal code not provide:

contenttype: 'application/json', 

you have:

accepts: 'application/json', 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -