Django:导入@wraps时为AppRegistryNotReady

时间:2018-09-21 15:38:22

标签: python django

使用{{ $data }}时收到以下错误。

wraps

安装装饰器,我在其中使用wraps函数。

File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/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 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 "/Users/Marc/Desktop/Dev/lumis/config/settings/local_marc.py", line 1, in <module>
    from .local import *
  File "/Users/Marc/Desktop/Dev/lumis/config/settings/local.py", line 1, in <module>
    from .base import *
  File "/Users/Marc/Desktop/Dev/lumis/config/settings/base.py", line 6, in <module>
    from lumis.core.helpers import get_env_variable
  File "/Users/Marc/Desktop/Dev/lumis/lumis/core/helpers.py", line 17, in <module>
    from .decorators import check_if_mixpanel_defined_in_settings
  File "/Users/Marc/Desktop/Dev/lumis/lumis/core/decorators.py", line 1, in <module>
    from django.contrib.auth.views import redirect_to_login
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/contrib/auth/views.py", line 11, in <module>
    from django.contrib.auth.forms import (
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/contrib/auth/forms.py", line 10, in <module>
    from django.contrib.auth.models import User
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
    class AbstractBaseUser(models.Model):
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/db/models/base.py", line 100, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/apps/registry.py", line 244, in get_containing_app_config
    self.check_apps_ready()
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/apps/registry.py", line 127, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

decorators.py

from functools import wraps

def check_if_mixpanel_defined_in_settings(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        if settings.MIXPANEL_ID:
            func(*args, **kwargs)
        else:
            print("Check for settings.MIXPANEL_ID failed.")
    return wrapper

0 个答案:

没有答案