[Answer]-Django-tastypie simple GET gives 400 error

1๐Ÿ‘

โœ…

I would need to see your url set up for the api to give you more help, but for starters the original url you provided:

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

and the one in your answer

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

do not call the same resource which makes it even harder to diagnose.

However, the first url is an absolute path and the second is relative which could be causing issues with your ALLOWED_HOSTS setting which could be generating the 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 a success function you will not see any results:

success: function(data, textStatus, jqXHR) {
    console.log(data);
}

that console.log is what makes you see a result in your console.

Your origanal code does not provide:

contentType: 'application/json',

You have:

accepts: 'application/json',
๐Ÿ‘คArctelix

0๐Ÿ‘

I think the problem is that the use of โ€œ/โ€ at end of the url is mandatory.
You should try with url: โ€˜url/to/site/contacts/api/v1/adresponses/1/โ€™,

when you visiting url/to/site/contacts/api/v1/adresponses/1 it redirect to url/to/site/contacts/api/v1/adresponses/1/, depending of your tastypie configuration

๐Ÿ‘คjpizarrom

Leave a comment