首页 > 解决方案 > 无法导入 rest_framework

问题描述

我在我的系统中安装了 Anaconda,但显然我已经为django API项目设置了一个新的干净的环境。我还为API安装了所有必要的要求。但是,当我尝试导入rest_framework时,即使我执行了以下操作,它也会提示“无法导入 'rest_framework'” :

#settings.py

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

#serializers.py

from rest_framework import serializers #<---- this line is giving me error
from .models import Plans   
    class PlansSerializer(serializers.ModelSerializer):
    """Serializer to map the Model instance into JSON format."""
class Meta: 
    """Meta class to map serializer's fields with the model fields."""
    model = Plans
    fields = ('id', 'name', 'date_created', 'date_modified')
    read_only_fields = ('date_created', 'date_modified') 

要求.txt

certifi==2018.11.29
Django==2.1.7
django-crispy-forms==1.7.2
django-filter==2.1.0
django-markdown==0.8.4
django-markdown2==0.3.1
django-pagedown==1.0.6
djangorestframework==3.9.2
djangorestframework-simplejwt==4.1.0
Markdown==3.0.1
markdown2==2.3.7
olefile==0.46
Pillow==5.4.1
Pygments==2.3.1
PyJWT==1.7.1
pytz==2018.9

我也总是停用 conda 的基础环境,只激活所需的环境。

标签: djangoapidjango-rest-framework

解决方案


推荐阅读