当尝试启动运行服务器时 它给了我这个错误,我不知道为什么,它以前工作正常
ModuleNotFoundError:没有名为“ drf_multiple_model”的模块
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/daniel/.local/share/virtualenvs/app-backend-RGL58hqa/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/home/daniel/.local/share/virtualenvs/app-backend-RGL58hqa/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/daniel/.local/share/virtualenvs/app-backend-RGL58hqa/lib/python3.6/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
raise _exception[0](_exception[1]).with_traceback(_exception[2])
File "/home/daniel/.local/share/virtualenvs/app-backend-RGL58hqa/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/home/daniel/.local/share/virtualenvs/app-backend-RGL58hqa/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/daniel/.local/share/virtualenvs/app-backend-RGL58hqa/lib/python3.6/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/daniel/.local/share/virtualenvs/app-backend-RGL58hqa/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/home/daniel/.local/share/virtualenvs/app-backend-RGL58hqa/lib/python3.6/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 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'drf_multiple_model'
答案 0 :(得分:1)
Django Rest Framework提供了一些令人难以置信的用于序列化数据的工具,但是有时您需要将许多序列化器和/或模型组合到单个API调用中。 drf-multiple-model是一款专为此目的设计的应用。
好吧,我想您找到了答案,但是如果其他人也遇到了同样的问题,也许就是这样:
pip install django-rest-multiple-models
请确保将drf_multiple_model
添加到您的INSTALLED_APPS中,然后将视图导入任何views.py
中。