Questions tagged [django-rest-framework]

A powerful and flexible toolkit for building RESTful Web APIs. Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

A Web API framework for Django. Suitable for building complex, highly customizable APIs and web services.

Features include:

  • Built-in support for various authentication, permissions, versioning, throttling and other API policies.
  • Creates APIs that can be interacted with directly in the browser (also known as Browsable APIs).
  • Large ecosystem of third party packages.

Documentation | GitHub | Mailing list


Related tags:

23552 questions
234
votes
7 answers

Django rest framework, use different serializers in the same ModelViewSet

I would like to provide two different serializers and yet be able to benefit from all the facilities of ModelViewSet: When viewing a list of objects, I would like each object to have an url which redirects to its details and every other relation…
BlackBear
  • 20,590
  • 9
  • 41
  • 75
176
votes
3 answers

How to disable admin-style browsable interface of django-rest-framework?

I am using django-rest-framework. It provides an awesome Django admin style browsable self-documenting API. But anyone can visit those pages and use the interface to add data (POST). How can I disable it?
iForests
  • 6,013
  • 9
  • 34
  • 70
171
votes
8 answers

Django REST Framework: adding additional field to ModelSerializer

I want to serialize a model, but want to include an additional field that requires doing some database lookups on the model instance to be serialized: class FooSerializer(serializers.ModelSerializer): my_field = ... # result of some database…
Neil
  • 6,236
  • 8
  • 37
  • 70
169
votes
1 answer

Django REST framework: non-model serializer

I am beginner in Django REST framework and need your advice. I am developing a web service. The service has to provide REST interface to other services. The REST interface, which I need to implement, is not working with my models directly (I mean…
Zakhar
  • 1,976
  • 2
  • 14
  • 14
164
votes
3 answers

How do I include related model fields using Django Rest Framework?

Let's say that we have the following model: class Classroom(models.Model): room_number = [...] class Teacher(models.Model): name = [...] tenure = [...] classroom = models.ForeignKey(Classroom) Let's say that instead of getting a…
Chaz
  • 2,742
  • 3
  • 17
  • 12
158
votes
11 answers

How to get Request.User in Django-Rest-Framework serializer?

I've tried something like this, it does not work. class PostSerializer(serializers.ModelSerializer): class Meta: model = Post def save(self): user = self.context['request.user'] title =…
PythonIsGreat
  • 5,861
  • 6
  • 19
  • 23
157
votes
7 answers

What are the differences between django-tastypie and djangorestframework?

Why would you use one over the other, for exposing an API for your Django app? http://pypi.python.org/pypi/djangorestframework/ http://pypi.python.org/pypi/django-tastypie
coffee-grinder
  • 25,040
  • 19
  • 53
  • 81
151
votes
9 answers

Disable a method in a ViewSet, django-rest-framework

ViewSets have automatic methods to list, retrieve, create, update, delete, ... I would like to disable some of those, and the solution I came up with is probably not a good one, since OPTIONS still states those as allowed. Any idea on how to do this…
db0
  • 3,279
  • 3
  • 21
  • 25
133
votes
14 answers

Django Rest Framework remove csrf

I know that there are answers regarding Django Rest Framework, but I couldn't find a solution to my problem. I have an application which has authentication and some functionality. I added a new app to it, which uses Django Rest Framework. I want to…
Irene Texas
  • 1,381
  • 2
  • 9
  • 8
129
votes
3 answers

Include intermediary (through model) in responses in Django Rest Framework

I have a question about dealing with m2m / through models and their presentation in django rest framework. Let's take a classic example: models.py: from django.db import models class Member(models.Model): name = models.CharField(max_length =…
mllm
  • 15,275
  • 14
  • 44
  • 58
128
votes
8 answers

How can I enable CORS on Django REST Framework

How can I enable CORS on my Django REST Framework? the reference doesn't help much, it says that I can do by a middleware, but how can I do that?
Julio Marins
  • 7,929
  • 7
  • 40
  • 48
126
votes
11 answers

Token Authentication for RESTful API: should the token be periodically changed?

I'm building a RESTful API with Django and django-rest-framework. As authentication mechanism we have chosen "Token Authentication" and I have already implemented it following Django-REST-Framework's documentation, the question is, should the…
nemesisdesign
  • 6,832
  • 10
  • 51
  • 90
120
votes
6 answers

TemplateDoesNotExist - Django Error

I'm using Django Rest Framework. and I keep getting an error Exception Type: TemplateDoesNotExist Exception Value: rest_framework/api.html I dont know how I'm going wrong. This is the first time I'm trying out hands on REST Framework. This is…
python-coder
  • 2,040
  • 4
  • 24
  • 36
119
votes
18 answers

Django Rest Framework - Could not resolve URL for hyperlinked relationship using view name "user-detail"

I am building a project in Django Rest Framework where users can login to view their wine cellar. My ModelViewSets were working just fine and all of a sudden I get this frustrating error: Could not resolve URL for hyperlinked relationship using…
bpipat
  • 3,270
  • 4
  • 18
  • 22
118
votes
12 answers

Django Rest Framework - Authentication credentials were not provided

I'm developing an API using Django Rest Framework. I'm trying to list or create an "Order" object, but when i'm trying to access the console gives me this error: {"detail": "Authentication credentials were not provided."} Views: from…
Marcos Aguayo
  • 5,393
  • 7
  • 25
  • 56
1
2 3
99 100