我正在学习Django Rest Framework。 我使用format_suffix_patterns支持Urls中的后缀 一切都很好,直到突然我开始出现错误
_frozen_importlib._DeadlockError:_ModuleLock('django.test.signals')在1367726740816处检测到死锁
和
OSError:[WinError 123]文件名,目录名称或卷标语法不正确:''
即使使用
导入“ format_suffix_patterns”from rest_framework.urlpatterns import format_suffix_patterns
给出错误。
但是在我开始使用视图集之前,没有问题。
我尝试删除了旧的环境并创建了一个新的环境 删除pycache并重试
这是造成错误的包含项
from rest_framework.urlpatterns import format_suffix_patterns
完整错误
Exception in thread django-main-thread:
Traceback (most recent call last):
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\template\utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\core\management\base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\contrib\admin\checks.py", line 79, in check_dependencies
for engine in engines.all():
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\template\utils.py", line 90, in all
return [self[alias] for alias in self]
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\template\utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\template\utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\template\backends\django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\template\backends\django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\template\backends\django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\template\backends\django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "E:\Web Development\messmanager\app\env\lib\site-packages\rest_framework\templatetags\rest_framework.py", line 15, in <module>
from rest_framework.renderers import HTMLFormRenderer
File "E:\Web Development\messmanager\app\env\lib\site-packages\rest_framework\renderers.py", line 20, in <module>
from django.test.client import encode_multipart
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\test\client.py", line 23, in <module>
from django.test import signals
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 149, in __enter__
File "<frozen importlib._bootstrap>", line 94, in acquire
_frozen_importlib._DeadlockError: deadlock detected by _ModuleLock('django.test.signals') at 1367726740816
Traceback (most recent call last):
File "E:/Web Development/messmanager/app_old/manage.py", line 21, in <module>
main()
File "E:/Web Development/messmanager/app_old/manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\utils\autoreload.py", line 585, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\utils\autoreload.py", line 570, in start_django
reloader.run(django_main_thread)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\utils\autoreload.py", line 288, in run
self.run_loop()
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\utils\autoreload.py", line 294, in run_loop
next(ticker)
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\utils\autoreload.py", line 334, in tick
for filepath, mtime in self.snapshot_files():
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\utils\autoreload.py", line 350, in snapshot_files
for file in self.watched_files():
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\utils\autoreload.py", line 249, in watched_files
yield from iter_all_python_module_files()
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\utils\autoreload.py", line 103, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "E:\Web Development\messmanager\app\env\lib\site-packages\django\utils\autoreload.py", line 136, in iter_modules_and_files
if not path.exists():
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\pathlib.py", line 1334, in exists
self.stat()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\pathlib.py", line 1156, in stat
return self._accessor.stat(self)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\pathlib.py", line 387, in wrapped
return strfunc(str(pathobj), *args)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap>'
答案 0 :(得分:0)
即使我遇到同样的错误。
我评论了以下代码,它对我有用。
from rest_framework.urlpatterns import format_suffix_patterns
urlpatterns = format_suffix_patterns(urlpatterns)