Django Rest Framework — no module named rest_framework

后端 未结 21 793
夕颜
夕颜 2021-02-01 00:23

I\'ve installed django rest framework using pip install djangorestframework yet I still get this error when I run \"python3 manage.py sycndb\":

相关标签:
21条回答
  • 2021-02-01 00:42

    If you are working with PyCharm, I found that restarting the program and closing all prompts after adding 'rest_framework' to my INSTALLED_APPS worked for me.

    0 讨论(0)
  • 2021-02-01 00:43

    First installing the framework globally on the system solved my problem.

    machine@debian:/$ sudo pip install djangorestframework
    or;
    root@debian:/# pip install djangorestframework
    
    0 讨论(0)
  • 2021-02-01 00:45

    I know there is an accepted answer for this question and many other answers also but I just wanted to add an another case which happened with me was Updating the django and django rest framework to the latest versions to make them work properly without any error.

    So all you have to do is just uninstall both django and django rest framework using:

    pip uninstall django pip uninstall djangorestframework

    and then install it again using:

    pip install django pip install djangorestframework

    0 讨论(0)
  • 2021-02-01 00:47

    You need to install django rest framework using pip3 (pip for python 3):

    pip3 install djangorestframework
    

    Instructions on how to install pip3 can be found here

    0 讨论(0)
  • 2021-02-01 00:47

    if you forget ,,this will happen,it's weird

    wrong example: need a ,

    INSTALLED_APPS = [
    'rest_framework'
    'django.contrib.contenttypes',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ]
    
    0 讨论(0)
  • 2021-02-01 00:47

    In my case, I had installed it in the virtualenv but forgot to activate the virtualenv while running the command

     python3 manage.py makemigrations 
    

    So in my case I had to just activate the environment and then run the command

    source [virtualenv folder-name]/bin/activate
    python3 manage.py makemigrations
    

    This solved my problem.

    0 讨论(0)
提交回复
热议问题