0

i've seen a lot of people having trouble with this here, and i always see them saying other to use pip3 or just pip to install it.

But in my case i've uninstalled it and installed id multiple times both using pip or pip3 and none of them seem to work.

I've added 'rest_framework' to my settings as well and still doesn't seem to work. Help me out please

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'
    ]
}

Collecting djangorestframework Downloading djangorestframework-3.7.3-py2.py3-none-any.whl (1.5MB) 100% |████████████████████████████████| 1.5MB 506kB/s Installing collected packages: djangorestframework Successfully installed djangorestframework-3.7.3

Still not working

EDIT 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
4

2 回答 2

4

尝试使用sudo pip install djangorestframework,我已经看到其他 SO 问题,它似乎解决了这个问题。

于 2017-12-12T00:55:06.953 回答
1

在 settings.py 文件中的已安装应用程序中添加rest_framework之前agenda.apps.AgendaConfig。似乎该agenda应用程序在初始化之前使用了一些 rest_framework 库。

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

    'rest_framework',
    'agenda.apps.AgendaConfig',


]

此答案假定您已成功安装 rest_framework 并激活 virtualenv

于 2017-12-12T11:52:27.407 回答