266👍
The fix
Just add Django’s Sites framework to your apps and set SITE_ID to 1 in your settings. List it prior to dependent libraries in the INSTALLED_APPS setting.
INSTALLED_APPS = [
'django.contrib.sites',
...
]
SITE_ID = 1
Why does this happen?
Django’s Sites Framework is a contributed module bundled with the core library that allows for the use of a single Django application/codebase with different sites (that can use different databases, logic in views, etc). The SITE_ID setting, as stated in the docs, "is used so that application data can hook into specific sites and a single database can manage content for multiple sites."
In this particular case AllAuth requires the Sites Framework in order to function properly. Many other third-party libraries are built to safely handle cases where multiple sites may be present and as such may be best .
9👍
I landed on this post via Google search. My problem was running tests that blew up with the error:
RuntimeError: Model class app.taxonomy.models.Term doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
This was running on Python 2.7.x with absolute imports. As mentioned by Colton Hicks in the comments, below, this can also happen with Python 3 (pytest 3.2.3 with Django 1.11.4).
In my tests.py
:
from __future__ import absolute_import
[...]
from .models import Demographics, Term
After changing the relative import to an absolute import the problem went away:
from taxonomy.models import Demographics, Term
HTH
- [Django]-How to limit the maximum value of a numeric field in a Django model?
- [Django]-How do Django models work?
- [Django]-UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 2: ordinal not in range(128)
4👍
I have django debug toolbar installed and this was actually causing the/my problem.
INSTALLED_APPS (in settings.py) needs the entry ‘django.contrib.sessions’. Make sure to run migrate after adding.
- [Django]-Django Rest Framework model serializer with out unique together validation
- [Django]-ValueError: The field admin.LogEntry.user was declared with a lazy reference
- [Django]-How to set up custom middleware in Django?
3👍
Try adding the app_label = 'yourApp'
in the models Meta class:
class Meta:
app_label = 'yourApp'
- [Django]-Django create userprofile if does not exist
- [Django]-Split views.py in several files
- [Django]-How do I filter query objects by date range in Django?
2👍
I got the error above. However my problem was the in the urls.py. I was following PyDanny cookiecutter django recipe. My error was to put in the urls.py this line:
url(r'^demo/', include('project.demoapp.urls', namespace='demoapp')),
when I corrected to this:
url(r'^demo/', include('demoapp.urls', namespace='demoapp')),
all was well. I also changed my local apps (I did this first and so the critical error was the url misconfiguration):
LOCAL_APPS = [
# Your stuff: custom apps go here
'demoapp.apps.DemoAppConfig',
]
- [Django]-How to expire session due to inactivity in Django?
- [Django]-Set Django IntegerField by choices=… name
- [Django]-Row level permissions in django
1👍
Just add 'django.contrib.sites',
to INSTALLED_APPS
and set SITE_ID = 1
in your settings.py
file.
- [Django]-Django: Redirect to previous page after login
- [Django]-How do I migrate a model out of one django app and into a new one?
- [Django]-What is a "slug" in Django?
1👍
Upgraded Answer for Django>=4.0 // 2022
Add Django’s Sites framework and FlatPages Framework to your INSTALLED_APPS and set SITE_ID in your settings.
INSTALLED_APPS = [
...
'django.contrib.sites',
'django.contrib.flatpages',
]
SITE_ID = 1
Your tests should work like a charm
- [Django]-Django TemplateSyntaxError – 'staticfiles' is not a registered tag library
- [Django]-Has Django served an excess of 100k daily visits?
- [Django]-AttributeError: 'module' object has no attribute 'tests'
1👍
Django 4.1+ (2023)
After almost an hour digging, what solved for me was this:
INSTALLED_APPS = [
...
'django.contrib.sessions',
]
No need for SITE_ID
or additional INSTALLED_APPS
entries.
- [Django]-Django Rest Framework – Updating a foreign key
- [Django]-No URL to redirect to. Either provide a url or define a get_absolute_url method on the Model
- [Django]-Django: remove a filter condition from a queryset
1👍
This error message typically occurs when Django encounters a model class that doesn’t have an explicit app_label defined and is not included in the INSTALLED_APPS list in your Django project’s settings.
To resolve this issue, you can follow these steps:
-
Open your Django project’s settings file (settings.py).
-
Locate the INSTALLED_APPS list, which should contain the names of all the installed apps in your project.
-
Make sure that the
'django.contrib.sessions'
app is included in the INSTALLED_APPS list.INSTALLED_APPS = [ # ... 'django.contrib.sessions', # ... ]
If you find that ‘django.contrib.sessions’ is missing, add it to the list as shown above and save the file.
If the app is already included in the INSTALLED_APPS list and you still encounter the error, there might be another issue with your project’s configuration. In that case, it’s worth verifying that you have the correct versions of Django and its dependencies installed, as compatibility issues can sometimes cause such errors.
Additionally, if you have custom model classes that don’t have an explicit app_label defined, you should add the app_label attribute to those model classes. For example:
class Session(models.Model):
# model fields
class Meta:
app_label = 'sessions'
By specifying the app_label attribute, you explicitly declare the app label for the model class, which helps Django locate and recognize it correctly. Replace ‘sessions’ with the appropriate label for your app.
Remember to restart your Django development server after making any changes to the settings file to ensure that the modifications take effect.
- [Django]-What is the most efficient way to store a list in the Django models?
- [Django]-Django dynamic forms – on-the-fly field population?
- [Django]-Django DoesNotExist
0👍
This error occurred because I had created a new app folder for a subset of sites related to another feature. This needed to be added to my INSTALLED_APPS in settings.py
- [Django]-How to check Django version
- [Django]-How to get an ImageField URL within a template?
- [Django]-Django: Group by date (day, month, year)
-2👍
Everything worked as expected after I made a migration
python manage.py migrate
Good luck
- [Django]-Unittest Django: Mock external API, what is proper way?
- [Django]-You are trying to add a non-nullable field 'new_field' to userprofile without a default
- [Django]-Multiple ModelAdmins/views for same model in Django admin