7

Django REST framework 项目运行测试时遇到导入出错

 2 years ago
source link: https://www.v2ex.com/t/804166
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Python

Django REST framework 项目运行测试时遇到导入出错

  veoco · 1 天前 · 470 次点击

运行测试的时候报错,看了下具体报错代码:

# rest_framework/test.py
from rest_framework.compat import coreapi, requests

if requests is not None:
    class HeaderDict(requests.packages.urllib3._collections.HTTPHeaderDict): # 这行出错

到最开始导入 requests 的地方:

# rest_framework/compat.py
try:
    import requests
except ImportError:
    requests = None

应该不会有问题啊,再看了下我的 Django 目录结构:

proj
├── proj
└── app1
│   └── test.py
└── app2
└── requests

我 Django 项目里有个叫 requests 的项目,这样就导致安装 DRF 后,在运行测试的时候导入了错误的包。

问题来了,有没有改应用名之外更好的解决方法?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK