Take the 2-minute tour ×

Just started with Django TastyPie to expose the data using JSON. Trying to tie together resources using tastypie.Api for urls.py

The example given in http://django-tastypie.readthedocs.org/en/latest/tutorial.html#creating-resources does NOT work out of the box.

My urls.py entry:

#now for the api
from tserver.api import PurchaseResource,DataResource

#combine several APIs
from tastypie.api import Api

api = Api(api_name='')

urlpatterns = patterns('', (r'^api/',include(api.urls)),

and the api.py:

#!/bin/env python

from tastypie.resources import ModelResource
from tastypie import fields
from tserver.models import Purchase,Data

class DataResource(ModelResource):
    class Meta:
        queryset = Data.objects.all()

class PurchaseResource(ModelResource):
    Info = fields.ForeignKey(DataResource,'data')
    class Meta:
        queryset = Purchase.objects.all()
        resource_name = 'purchase'

and models.py:

class Data(models.Model):
    tagID    = models.CharField(max_length=40)
    dtime    = models.DateTimeField()
    vcardf   = models.CharField(max_length = 600)

class Purchase(models.Model):
    Info        = models.ForeignKey('Data',unique=True)
    payment_method = models.CharField(max_length=20,choices=PAYMENT_METHOD)
    TotalAmount    = models.DecimalField(max_digits = 20, decimal_places=2)
    TotalDiscount  = models.DecimalField(max_digits = 20, decimal_places=2)
    valid_upto     = models.DateTimeField()

and finally when I try it out, the errors:


results in:

Page not found (404)
Request Method:     GET
Request URL:    http://localhost:8000/api/data/1/?format=json

Using the URLconf Django tried these URL patterns, in this order:

^(?P<api_name>)/$ [name='api__top_level']

The current URL, api/data/1/, didn't match any of these.

But this problem is NOT there if I just use in urls.py:

urlpatterns = patterns('', (r'^api/',include(DataResoure().urls)),

What is the issue here when we try to tie things together with api.register(...) ?

share|improve this question

1 Answer 1

We always specify api_name and resource name. Like

registration file

public_api = Api(api_name='public')

private_api = Api(api_name='private')


urlpatterns = patterns('',
    url(r'^api/', include(public_api.urls)),
    url(r'^api/', include(private_api.urls)),

and we get url:



I want to warn you, tastypie shown a very bad productivity, and contains some serious issues, that may lead to data loss, we did a lot of monkey patching before it started to work nice. Currently we are moving to our own framework. I strongly recommend you to use something smaller like piston, but its not a silver bullet too.

share|improve this answer
thanks for your comments. What sort of issues you have faced with tastypie ? Is it security breach or is it performance issues. Could you please elaborate...that will help me in making my decision..and may help others who wants to use this. –  user1102171 Jan 2 '12 at 14:09
Performance issues are significant, serialization is very slow. Saving large amount of models is very db intensive. Sending PUT and POST of models may cause data loss. Working with related models (ForeignKey and M2M) is messy. It's hard to prohibit saving of related models without code duplication. Nested resources are hard to use. No file upload support out of the box. When creating multiple models Location header is not returned at all. May be I forgot something. –  asdasd Jan 3 '12 at 12:06
Did I answer your question? –  asdasd Jan 5 '12 at 0:40
@asdasd: regards the issues you pointed out in tastypie, do you have more details about under what conditions do they happen, or a link to the corresponding issue in their github repo? –  Z. Lin Nov 20 '13 at 1:22

Your Answer


