title: Django: AppRegistryNotReady when importing @wraps
body: <p>I receive the following error when using <code>wraps</code>. </p>
  
  <pre><code>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 "&lt;frozen importlib._bootstrap&gt;", line 994, in _gcd_import
    File "&lt;frozen importlib._bootstrap&gt;", line 971, in _find_and_load
    File "&lt;frozen importlib._bootstrap&gt;", line 955, in _find_and_load_unlocked
    File "&lt;frozen importlib._bootstrap&gt;", line 665, in _load_unlocked
    File "&lt;frozen importlib._bootstrap_external&gt;", line 678, in exec_module
    File "&lt;frozen importlib._bootstrap&gt;", line 219, in _call_with_frames_removed
    File "/Users/Marc/Desktop/Dev/lumis/config/settings/local_marc.py", line 1, in &lt;module&gt;
      from .local import *
    File "/Users/Marc/Desktop/Dev/lumis/config/settings/local.py", line 1, in &lt;module&gt;
      from .base import *
    File "/Users/Marc/Desktop/Dev/lumis/config/settings/base.py", line 6, in &lt;module&gt;
      from lumis.core.helpers import get_env_variable
    File "/Users/Marc/Desktop/Dev/lumis/lumis/core/helpers.py", line 17, in &lt;module&gt;
      from .decorators import check_if_mixpanel_defined_in_settings
    File "/Users/Marc/Desktop/Dev/lumis/lumis/core/decorators.py", line 1, in &lt;module&gt;
      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 &lt;module&gt;
      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 &lt;module&gt;
      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 &lt;module&gt;
      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 &lt;module&gt;
      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.
  </code></pre>
  
  <p>Attached the decorator, where I am using the wraps function.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>decorators.py</p>
  
  <pre><code>from django.contrib.auth.views import redirect_to_login
  from django.core.exceptions import PermissionDenied
  from functools import wraps
  from django.conf import settings
  
  
  def admin_permission_required(view_func):
      """
      A view decorator that ensures that the user is logged in
      and has access to the organizer in the request.
      If the user is not logged in, he will be redirected to
      the login page with the matching next parameter.
      If the user does not have permission for the organizer
      a PermissionDenied exception is raised.
      """
      def wrapper(request, *args, **kwargs):
          # Make sure that this decorator is only used if the organizer object exists in the request
          assert hasattr(request, 'organizer'), (
              "The admin_permission_required decorator "
              "requires the organizer object in the request."
          )
  
          # Check if the user is authenticated
          if not request.user.is_authenticated:
              return redirect_to_login(request.get_full_path())
  
          # Check if the user belongs to the organizer
          if request.organizer.user == request.user:
              return view_func(request, *args, **kwargs)
  
          raise PermissionDenied("You don't have permissions for this organizer.")
      return wrapper
  
  
  class AdminPermissionRequiredMixin:
      """
      Mixin to use the admin_permission_required decorator in a class-based view.
      """
      @classmethod
      def as_view(cls, **initkwargs):
          view = super().as_view(**initkwargs)
          return admin_permission_required(view)
  
  
  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
  </code></pre>