tastypie

Django-tastypie. Output in JSON to the browser by default

穿精又带淫゛_ 提交于 2019-12-04 15:31:27
问题 I see 'Sorry, not implemented yet. Please append "?format=json" to your URL.'. I need always append string "?format=json". Can I make a output in JSON by default? Regards, Vitaliy 回答1: From the tastypie cookbook, in order to change the default format, you need to override the determine_format() method on your ModelResource: class MyResource(ModelResource): .... def determine_format(self, request): return 'application/json' The above link demonstrates alternative methods of determining output

django-tastypie PATCH gives me a “400 (Bad Request)”

那年仲夏 提交于 2019-12-04 12:37:16
I am running a Django site on Apache which is front'ed by Nginx instance to serve my static media. I expose an API via django-tastypie to a model that I need to PATCH a field on. When I do local testing (via the django runserver) everything works as expected. On the live server however I get "400 (Bad Request)" returned. I've read a few places saying that Nginx does not support PATCH? Is that right? Is there a good workaround for this? Am I doing something wrong? I only send through the fields I want to update via the postData . JQuery Code: $.ajax({url: '...', type: 'PATCH', accepts:

Tastypie, filtering many to many relationships

心不动则不痛 提交于 2019-12-04 12:05:03
问题 I have two models that are linked by another model through a many to many relationship. Here's the models themselves class Posts(models.Model): id = models.CharField(max_length=108, primary_key=True) tags = models.ManyToManyField('Tags', through='PostTags') class Tags(models.Model): id = models.CharField(max_length=108, primary_key=True) posts = models.ManyToManyField('Posts', through='PostTags') class PostTags(models.Model): id = models.CharField(max_length=108, primary_key=True) deleted =

PUT request to django tastypie resource not working

可紊 提交于 2019-12-04 10:23:02
i'm trying to do a put request to my django tastypie resource in order to update user info. Up to now, i can make post request but put is not working. In my api.py i have this: class UserResource(ModelResource): class Meta: queryset = User.objects.all() resource_name = 'auth/user' fields = ['username', 'email'] authentication = BasicAuthentication() authorization = DjangoAuthorization() filtering = { "username": ('exact',), } class UserSignUpResource(ModelResource): class Meta: object_class = User resource_name = 'register_user' fields = ['username', 'email' , 'password'] allowed_methods = [

Tastypie accessing fields from inherited models

别等时光非礼了梦想. 提交于 2019-12-04 08:43:43
Is it possible to include fields on related models, using tastypie? As per my models below: if I persist one VideoContent and one TextContent instance to the DB, I can then get 2 objects back from my Content resource, however none of the additional fields are available. Is it possible to include fields from related models (in this instance, the video url and the text content) and will that cater for adding more Content types in the future without having to rewrite the Content Resource, or am I coming at this from the wrong direction? The goal is to be able to extend this with more ContentTypes

RESTFUL web services consumed by web and native mobile apps with authentication in python using django framework

▼魔方 西西 提交于 2019-12-04 08:39:34
问题 I have to write RESTFUL web-services with authentication in python using django framework which will be consumed by web based clients and mobile native apps (Android and IOS). the simple example would be that user will log in using email and password, he fetches the api key and stores it on the mobile device and then use this api key for consuming further api's instead of giving user credentials again and again. I am thinking of using TASTYPIE or Django piston for writing RESTFUL services but

REST urls with tastypie

僤鯓⒐⒋嵵緔 提交于 2019-12-04 08:02:07
I'm using tastypie in my django application and I'm trying to get it to map urls like "/api/booking/2011/01/01" which maps to a Booking model with the specified timestamp in the url. The documentation falls short of telling how to achieve this. What you want to do in your Resource is provide an def prepend_urls(self): return [ url(r"^(?P<resource_name>%s)/(?P<year>[\d]{4})/(?P<month>{1,2})/(?<day>[\d]{1,2})%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('dispatch_list_with_date'), name="api_dispatch_list_with_date"), ] method, which returns a url, which points to a view (I

Does SessionAuthentication work in Tastypie for HTTP POST?

江枫思渺然 提交于 2019-12-04 06:54:43
I am able to do GET to work with SessionAuthentication and Tastypie without setting any headers except for content-type to application/json . HTTP POST however just fails even though the Cookie in the Header has the session id. It fails with a 401 AuthorizationHeader but it has nothing to do with Authorization. Changing SessionAuthentication to BasicAuthentication and passing username/password works too. Has anyone ever got SessionAuthentication to work with POST with Tastypie? Yes I have gotten it to work. All you need to do is to pass the csfr token: SessionAuthentication This authentication

Django database error: missing table social_auth_usersocialauth when social_auth is not installed

前提是你 提交于 2019-12-04 06:25:36
I'm trying to deal with a very puzzling error in a Django app. When DEBUG=False, trying to delete a user (via user.delete() ) gives this database error: DatabaseError: relation "social_auth_usersocialauth" does not exist LINE 1: ...", "social_auth_usersocialauth"."extra_data" FROM "social_au... However, I do not have social_auth or anything by a similar name in INSTALLED_APPS, nor are there any such tables in my database, nor does any of my code reference anything of the sort (I ran a text search on 'social' in the entire project folder) - and again, this works fine when DEBUG=True. social

Tastypie: How can I fill the resource without database?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 06:23:30
I want to grab some information from Foursquare , add some fields and return it via django-tastypie. UPDATE: def obj_get_list(self, request=None, **kwargs): near = '' if 'near' in request.GET and request.GET['near']: near = request.GET['near'] if 'q' in request.GET and request.GET['q']: q = request.GET['q'] client = foursquare.Foursquare(client_id=settings.FSQ_CLIENT_ID, client_secret=settings.FSQ_CLIENT_SECRET) a = client.venues.search(params={'query': q, 'near' : near, 'categoryId' : '4d4b7105d754a06374d81259' }) objects = [] for venue in a['venues']: bundle = self.build_bundle(obj=venue,