1👍
✅
Put in your app/apps/user/api.py
from tastypie.resources import ModelResource
from django.contrib.auth.models import User
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
And in your urls.py
from django.conf.urls.defaults import *
from app.apps.user.api import UserResource
v1_api = Api(api_name='v1') #api_name will be 'v1' in http://localhost:8000/v1/?format=json
v1_api.register(UserProfileResource())
urlpatterns = patterns('',
(r'^api/', include(v1_api.urls)),
)
I don’t mean to be crude here, but reading the documentation, specially the quickstart, would help.
Your api is now (in your devserver) exposed to
http://localhost:8000/api/v1/?format=json
Thats all. You don’t have to write any code, for example to
- retrieve all users in json:
http://localhost:8000/api/v1/user/?format=json
- retrieve the entry in the user table with the key 1
http://localhost:8000/api/v1/user/1/?format=json
- retrieve the meta information about your UserResource
http://localhost:8000/api/v1/user/schema/?format=json
Hope this helps you!
👤jazz
Source:stackexchange.com