Questions tagged [django-rest-framework]

Django REST framework is 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.

Django REST framework is a Web API framework for Django and is 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:

31358 questions
309
votes
9 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
  • 22,411
  • 10
  • 48
  • 86
217
votes
4 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,757
  • 10
  • 42
  • 75
216
votes
11 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
  • 7,042
  • 9
  • 43
  • 78
214
votes
12 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
  • 10,039
  • 8
  • 48
  • 54
214
votes
15 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
  • 7,529
  • 7
  • 21
  • 26
190
votes
5 answers

What's the appropriate HTTP status code to return if a user tries logging in with an incorrect username / password, but correct format?

A similar question is posted here: What's an appropriate HTTP status code to return by a REST API service for a validation failure? The answer in the thread above states that "For instance if the URI is supposed to have an ISO-8601 date and you find…
189
votes
4 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
  • 3,232
  • 5
  • 19
  • 12
188
votes
13 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,689
  • 3
  • 23
  • 26
183
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
  • 2,143
  • 2
  • 15
  • 15
182
votes
35 answers

django.db.migrations.exceptions.InconsistentMigrationHistory

When I run python manage.py migrate on my Django project, I get the following error: Traceback (most recent call last): File "manage.py", line 22, in execute_from_command_line(sys.argv) File "/home/hari/project/env/local/lib/python2.7/site-…
168
votes
17 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,731
  • 2
  • 12
  • 8
160
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
  • 26,940
  • 19
  • 56
  • 82
159
votes
20 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
  • 6,840
  • 8
  • 28
  • 61
158
votes
14 answers

Django: TemplateDoesNotExist (rest_framework/api.html)

In my view function, I'd like to return a json object (data1) and some text/html (form). Is this possible? MY code @api_view(['POST']) @permission_classes((AllowAny,)) def create_user(request): if request.is_ajax(): if request.method ==…
Coeus
  • 2,385
  • 3
  • 17
  • 27
155
votes
22 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,700
  • 4
  • 20
  • 22
1
2 3
99 100