django - 无法导入 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 的基础环境,只激活所需的环境。
解决方案
推荐阅读
- r - 如何在不使用 for 循环的情况下替换数据框中的某些行
- angular - 在 Angular/typescript 中输入提示
- angular - 运行 ng build 导致错误:无法创建长度超过 0x3fffffe7 个字符的字符串
- python - 将 numpy 数组的实部和虚部元素四舍五入,向零或远离零四舍五入
- object - Tradingview Pine - 如何访问用户绘制的水平线的价格
- c# - 在 TextBox/TextBlock 中显示数据
- ruby - Ruby 方法调用 element.send() 抛出 ArgumentError
- reactjs - 如何将 Material UI 的 ThemeProvider 与 next.js 一起使用?
- vue.js - Vuex 中具有多个属性值的有效负载
- python - 如何将列添加到聚类算法中