7-9 drf实现发送短信验证码接口-2

 

按照视频,配置好

# 配置
router.register(r'codes', SmsCodeViewset)

之后 运行就报错:

Performing system checks...

Unhandled exception in thread started by <_pydev_bundle.pydev_monkey._NewThreadStartupWithTrace object at 0x000002364339EDD8>
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pydev\_pydev_bundle\pydev_monkey.py", line 614, in __call__
    return self.original_func(*self.args, **self.kwargs)
  File "D:\Envs\MxShop\lib\site-packages\django\utils\autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "D:\Envs\MxShop\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "D:\Envs\MxShop\lib\site-packages\django\core\management\base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "D:\Envs\MxShop\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "D:\Envs\MxShop\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "D:\Envs\MxShop\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "D:\Envs\MxShop\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
    return check_method()
  File "D:\Envs\MxShop\lib\site-packages\django\urls\resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "D:\Envs\MxShop\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\Envs\MxShop\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "D:\Envs\MxShop\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\Envs\MxShop\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\huang\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 978, in _gcd_import
  File "", line 961, in _find_and_load
  File "", line 950, in _find_and_load_unlocked
  File "", line 655, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 205, in _call_with_frames_removed
  File "C:\Users\huang\PycharmProjects\MxShop\MxShop\urls.py", line 39, in 
    router.register(r'codes', SmsCodeViewset)
  File "D:\Envs\MxShop\lib\site-packages\rest_framework\routers.py", line 102, in register
    basename = self.get_default_basename(viewset)
  File "D:\Envs\MxShop\lib\site-packages\rest_framework\routers.py", line 185, in get_default_basename
    assert queryset is not None, '`basename` argument not specified, and could ' \
AssertionError: `basename` argument not specified, and could not automatically determine the name from the viewset, as it does not have a `.queryset` attribute.

 

解决办法:

# 配置
router.register(r'codes', SmsCodeViewset, base_name="codes")

 

访问:http://127.0.0.1:8000/codes/

报错:

 

解决办法:

在项目的setting.py中设置

# REST_FRAMEWORK = {
#     'DEFAULT_AUTHENTICATION_CLASSES': (
#         'rest_framework.authentication.BasicAuthentication',
#         'rest_framework.authentication.SessionAuthentication',
#         'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
#     )
# }
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': []
}

效果:

7-9 drf实现发送短信验证码接口-2_第1张图片

 

输入完整手机号:

7-9 drf实现发送短信验证码接口-2_第2张图片

 

手机成功收到信息

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(REST,f)