我看到很多人在这里遇到麻烦,我总是看到他们说别人使用pip3或者只是用pip来安装它。
但在我的情况下,我已经卸载它并使用pip或pip3多次安装id,但它们似乎都不起作用。
我已将'rest_framework'添加到我的设置中,但似乎仍无法正常工作。 请帮帮我
EDIT
Here is my settings
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'agenda.apps.AgendaConfig',
'rest_framework',
]
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}
收集djangorestframework下载 djangorestframework-3.7.3-py2.py3-none-any.whl(1.5MB) 100%|████████████████████████████████| 1.5MB 506kB / s安装收集的软件包:djangorestframework已成功安装 djangorestframework-3.7.3
仍然无法正常工作
编辑2
> Traceback (most recent call last): File
> "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py",
> line 226, in wrapper
> fn(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py",
> line 121, in inner_run
> self.check(display_num_errors=True) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> line 374, in check
> include_deployment_checks=include_deployment_checks, File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> line 361, in _run_checks
> return checks.run_checks(**kwargs) File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py",
> line 81, in run_checks
> new_errors = check(app_configs=app_configs) File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py",
> line 14, in check_url_config
> return check_resolver(resolver) File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py",
> line 24, in check_resolver
> for pattern in resolver.url_patterns: File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py",
> line 35, in __get__
> res = instance.__dict__[self.name] = self.func(instance) File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py",
> line 313, in url_patterns
> patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File
> "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py",
> line 35, in __get__
> res = instance.__dict__[self.name] = self.func(instance) File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py",
> line 306, in urlconf_module
> return import_module(self.urlconf_name) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
> __import__(name) File "/home/cyro/PycharmProjects/MyClinic/MyClinic/urls.py", line 20, in
> <module>
> url(r'^agenda/', include('agenda.urls')), File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py",
> line 50, in include
> urlconf_module = import_module(urlconf_module) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
> __import__(name) File "/home/cyro/PycharmProjects/MyClinic/agenda/urls.py", line 3, in
> <module>
> from . import views File "/home/cyro/PycharmProjects/MyClinic/agenda/views.py", line 8, in
> <module>
> import rest_framework ImportError: No module named rest_framework
答案 0 :(得分:1)
尝试使用sudo pip install djangorestframework
,我已经看过其他SO问题,似乎解决了这个问题。
答案 1 :(得分:1)
在{。1}}之前的{。{1}}中,在settings.py文件中的已安装应用中添加rest_framework
。似乎agenda.apps.AgendaConfig
app在初始化之前使用了一些rest_framework库。
agenda
此答案假定您已成功安装rest_framework并已激活virtualenv