我有一个现有的,工作的Django应用程序,它实现了许多Django-REST框架API。 现在,我正在尝试添加用户身份验证API,如Django-rest-framework-JWT中所述。但它没有用。
首先,我使用pip
安装了Django-rest-framework-JWT。没问题。
然后我将以下块添加到REST_FRAMEWORK
中的settings.py
变量:
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
最后,我在应用程序目录中的urls.py
添加了以下行(IE:不是全局urls.py
):
url(r'^api-token-auth/', 'rest_framework_jwt.views.obtain_jwt_token'),
当我启动服务器时,我收到了以下丑陋的错误:ValueError: Empty module name
。为什么我会收到此错误以及如何解决?
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/core/management/__init__.py", line 75, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/south/management/commands/__init__.py", line 10, in <module>
import django.template.loaders.app_directories
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/template/loaders/app_directories.py", line 23, in <module>
mod = import_module(app)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/authority/__init__.py", line 2, in <module>
from authority.sites import site, get_check, get_choices_for, register, unregister
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/authority/sites.py", line 7, in <module>
from authority.permissions import BasePermission
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/authority/permissions.py", line 9, in <module>
from authority.models import Permission
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/authority/models.py", line 10, in <module>
from authority.utils import User
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/authority/utils.py", line 11, in <module>
User = get_user_class()
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/authority/utils.py", line 6, in get_user_class
return auth.get_user_model()
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 127, in get_user_model
user_model = get_model(app_label, model_name)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/db/models/loading.py", line 271, in get_model
self._populate()
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/db/models/loading.py", line 75, in _populate
self.load_app(app_name, True)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/registration/models.py", line 15, in <module>
User = get_user_model()
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 127, in get_user_model
user_model = get_model(app_label, model_name)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/db/models/loading.py", line 271, in get_model
self._populate()
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/db/models/loading.py", line 75, in _populate
self.load_app(app_name, True)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/db/models/loading.py", line 97, in load_app
app_module = import_module(app_name)
File "/opt/virtualEnvs/myApp/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ValueError: Empty module name