记录第一次使用Django(DRF)报错

报错代码*

April 03, 2024 - 23:09:51
Django version 3.2.25, using settings 'dj1.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "D:\django_virtualenv\django_1\lib\site-packages\django\utils\module_loading.py", line 13, in import_string
    module_path, class_name = dotted_path.rsplit('.', 1)
ValueError: not enough values to unpack (expected 2, got 1)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\django_virtualenv\django_1\lib\site-packages\django\core\servers\basehttp.py", line 45, in get_internal_wsgi_application
    return import_string(app_path)
  File "D:\django_virtualenv\django_1\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "d:\python安装\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "D:\python存储\Django\django_1\dj1\dj1\wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "D:\django_virtualenv\django_1\lib\site-packages\django\core\wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "D:\django_virtualenv\django_1\lib\site-packages\django\core\handlers\wsgi.py", line 127, in __init__
    self.load_middleware()
  File "D:\django_virtualenv\django_1\lib\site-packages\django\core\handlers\base.py", line 40, in load_middleware
    middleware = import_string(middleware_path)
  File "D:\django_virtualenv\django_1\lib\site-packages\django\utils\module_loading.py", line 15, in import_string
    raise ImportError("%s doesn't look like a module path" % dotted_path) from err
ImportError: rest_framework doesn't look like a module path

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "d:\python安装\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "d:\python安装\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "D:\django_virtualenv\django_1\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "D:\django_virtualenv\django_1\lib\site-packages\django\core\management\commands\runserver.py", line 138, in inner_run
    handler = self.get_handler(*args, **options)
  File "D:\django_virtualenv\django_1\lib\site-packages\django\contrib\staticfiles\management\commands\runserver.py", line 27, in get_handler
    handler = super().get_handler(*args, **options)
  File "D:\django_virtualenv\django_1\lib\site-packages\django\core\management\commands\runserver.py", line 65, in get_handler
    return get_internal_wsgi_application()
  File "D:\django_virtualenv\django_1\lib\site-packages\django\core\servers\basehttp.py", line 50, in get_internal_wsgi_application
    ) from err
django.core.exceptions.ImproperlyConfigured: WSGI application 'dj1.wsgi.application' could not be loaded; Error importing module.

根据报错
检查中间件配置: 检查您在Django项目的settings.py文件中定义的中间件配置。确保其中每个中间件的路径都正确,并且没有任何拼写错误或其他问题。

检查模块路径: 如果您自定义了中间件或者指定了自定义的模块路径,请确保路径正确,并且模块存在于指定的位置。

查看相关代码行: 检查堆栈跟踪中涉及到的代码行,特别是settings.py文件中的中间件配置行以及wsgi.py文件中的应用程序配置行。这可能会提供更多关于问题的线索。

检查Django版本和依赖项: 确保您正在使用的Django版本与您的代码兼容,并且您的依赖项已正确安装。
回想:之前没报错是的代码,是添加(DRF 配置时才出现的报错)
打开settings.py 查看才发现
在这里插入图片描述
之前导入子应用的时候 把它写进了中间件中,才引发的报错所以只需要 把它写会注册应用
MIDDLEWARE = [

'rest_framework',

]
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值