0

I do my first steps with the Django REST Framework. But when I do:

python3 manage.py makemigrations && python3 manage.py migrate

I get this error:

ModuleNotFoundError: No module named 'rest_framework.renderers'

I have checked the settings.py:

INSTALLED_APPS = [
    'api',
    'rest_framework',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

I checked pip3 if the package is installed:

Django==3.0.5
django-rest-framework==0.1.0
djangorestframework==3.11.0

This is the code snippet where I use it and where I get the error:

from django.http import HttpResponse
from rest_framework.renderers import JSONRenderer
from rest_framework.decorators import api_view
from .models import Repo, Category
from .serializers import repoSerializer, categorySerializer

I do not know where the error is. Can somebody give me a hint? Is maybe there a problem with the migration?

1 Answer 1

1

You have to include this in settings.py

REST_FRAMEWORK = {
    'DEFAULT_RENDERER_CLASSES': [
        'rest_framework.renderers.JSONRenderer',
    ]
}

For more info: https://www.django-rest-framework.org/api-guide/renderers/

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but get still the same error. Can I reset the migrations, maybe there is something in the cache.
It is not related to migration atm. For reverting, take a look at this: stackoverflow.com/a/32124113/7994074
I cloud find the problem, something is wrong with my python under macOS. I need to run it as root. Then everything works perfectly. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.