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?

beli3ver
  • 363
  • 3
  • 15

1 Answers1

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/

ParthS007
  • 2,581
  • 1
  • 22
  • 37
  • Thanks, but get still the same error. Can I reset the migrations, maybe there is something in the cache. – beli3ver Apr 16 '20 at 06:48
  • It is not related to migration atm. For reverting, take a look at this: https://stackoverflow.com/a/32124113/7994074 – ParthS007 Apr 16 '20 at 06:52
  • 1
    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. – beli3ver Apr 16 '20 at 09:34