web-dev-qa-db-ja.com

「Django.contrib.staticfiles.templatetags」という名前のモジュールはありません

私は一日中これについて頭を抱えていますが、問題を理解することができません。 DjangoプロジェクトをPC間でコピーした後に発生しました。

Watching for file changes with StatReloader
Exception in thread Django-main-thread:
Traceback (most recent call last):
  File "/Users/username/opt/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/Users/username/opt/anaconda3/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/username/opt/anaconda3/lib/python3.7/site-packages/Django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/Users/username/opt/anaconda3/lib/python3.7/site-packages/Django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/Users/username/opt/anaconda3/lib/python3.7/site-packages/Django/utils/autoreload.py", line 76, in raise_last_exception
    raise _exception[1]
  File "/Users/username/opt/anaconda3/lib/python3.7/site-packages/Django/core/management/__init__.py", line 357, in execute
    autoreload.check_errors(Django.setup)()
  File "/Users/username/opt/anaconda3/lib/python3.7/site-packages/Django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/Users/username/opt/anaconda3/lib/python3.7/site-packages/Django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/username/opt/anaconda3/lib/python3.7/site-packages/Django/apps/registry.py", line 122, in populate
    app_config.ready()
  File "/Users/username/opt/anaconda3/lib/python3.7/site-packages/Django/contrib/admin/apps.py", line 24, in ready
    self.module.autodiscover()
  File "/Users/username/opt/anaconda3/lib/python3.7/site-packages/Django/contrib/admin/__init__.py", line 26, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "/Users/username/opt/anaconda3/lib/python3.7/site-packages/Django/utils/module_loading.py", line 47, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/Users/username/opt/anaconda3/lib/python3.7/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 "/Users/saitohiromasa/opt/anaconda3/lib/python3.7/site-packages/Django_summernote/admin.py", line 5, in <module>
    from Django_summernote.widgets import SummernoteWidget, SummernoteInplaceWidget
  File "/Users/username/opt/anaconda3/lib/python3.7/site-packages/Django_summernote/widgets.py", line 4, in <module>
    from Django.contrib.staticfiles.templatetags.staticfiles import static
ModuleNotFoundError: No module named 'Django.contrib.staticfiles.templatetags'

Settings.pyで:

INSTALLED_APPS = [
    'Django_summernote',
    'accounts.apps.AccountsConfig',
    'blogs.apps.BlogsConfig',
    'Django.contrib.admin',
    'Django.contrib.auth',
    'Django.contrib.contenttypes',
    'Django.contrib.sessions',
    'Django.contrib.messages',
    'Django.contrib.staticfiles',
]

私のDjangoバージョンは3.0です。ここで何が問題になっているのでしょうか?私を助けてください。ありがとう!

6
user7421972

しばらくの間、これはかなり一般的なことですが、今後数年間で全員がDjango 3に移行し始めます。

受け入れられた回答に加えて、これはDjango 2とDjango 3 static imports(esp 。パッケージの管理に役立ちます)

try:
    # Django 2
    from Django.contrib.staticfiles.templatetags.staticfiles import static
except ModuleNotFoundError:
    # Django 3
    from Django.templatetags.static import static
0
Kalob Taulien