Jump to content

Django for Designers/Whats next: Difference between revisions

→‎create blank api.py file and add it to urls.py: Fix security and explain example more
imported>Paulproteus
imported>Paulproteus
(→‎create blank api.py file and add it to urls.py: Fix security and explain example more)
Line 328:
class BookmarkResource(ModelResource):
class Meta:
allowed_methods = ['get']
queryset = Bookmark.objects.all()
resource_name = 'bookmark'
</source>
 
Tastypie is based on "Resources"; you can read more about it in its [http://django-tastypie.readthedocs.org/en/latest/tutorial.html own tutorial]. In this example, we do just a handful of things:
 
* We limit users of the API to only be able to ''get'' from you, rather than use other HTTP verbs like PUT and DELETE to upload or modify data. (You can enable PUT and similar modification features yourself, but you will likely want to learn about authorization within Tastypie first.)
 
* It will make available the ''queryset'' provided, which is all the bookmarks.
 
* The resource_name setting configures one URL fragment that will be required, namely that it will be available at .../bookmark/.
 
For this file to be invoked in request processing, we have to tie it into a url. So let's edit ''urls.py''. First, add a new import to the top of the file:
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.