Wagtail and allauth - allauth is inheriting site name from django not wagtail - django

I am using allauth with wagtail. I have name my site 'mysite' in the wagtail admin, but when sign up emails refer to 'example.com'
My settings.py has apps in the following order
[ ...
'django.contrib.auth',
'django.contrib.sites',
"allauth",
"allauth.account",
"allauth.socialaccount",
"allauth.account",
"allauth.socialaccount",
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail.core',
]
It sounds as though this might be related to the conflict between django and wagtail described here https://github.com/wagtail/wagtail/issues/2840. However it looks as though that issue has been closed and I am using recent version (Django==3.2.11, django-allauth==0.47.0, wagtail==2.15.1)

This is the expected behaviour - django-allauth is a Django package, not a Wagtail-specific one, and always uses Django's site model even when Wagtail is active. To update the site name, log in to the Django admin backend (as distinct from the Wagtail one - this can be found at http://localhost:8000/django-admin/ if you set up your project with the wagtail start command) and go to the Sites item.
The issue being fixed in https://github.com/wagtail/wagtail/issues/2840 was that Wagtail and django-allauth could not coexist at all, due to both of them trying to set a conflicting request.site variable.

Related

RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS

I am building an application with Django Rest Framework and AngularJs. I am using Django-rest-auth for my authentication purposes, although, I have not been able to set it up. Anyway, I am trying to set up this app with my project. I realized I need to install django-rest-auth-registration to get it running, so I followed this documentation to do the following things:
I ran the commands
pip install django-rest-auth
and
pip install django-allauth
Any my settings.py looks like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# 3rd party apps
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'allauth',
'allauth.account',
'rest_auth.registration',
# My app
'myapp',
]
I have also added the authentication backends, context_processors, and the proper urls.
However, when I try to migrate, my terminal throws the following error:
RuntimeError: Model class django.contrib.sites.models.Site doesn't
declare an explicit app_label and isn't in an application in
INSTALLED_APPS.
Why do I get this error, and how do I solve it to migrate my project? Thanks!
The fix
Just add Django's Sites framework to your apps and set SITE_ID to 1 in your settings.
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 .
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
Try adding the app_label = 'yourApp' in the models Meta class:
class Meta:
app_label = 'yourApp'
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',
]
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.
Just add 'django.contrib.sites', to INSTALLED_APPS and set SITE_ID = 1 in your settings.py file.
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
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 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.
Everything worked as expected after I made a migration
python manage.py migrate
Good luck

Plugging Askbot into existing Django project, Aunthentication and integrating the users

I installed askbot through pip into my existing local Django project. I merged the askbot settings & Uls files with my existing files. When I go to 127.0.0.1:8000/ its getting redirected to 127.0.0.1:8000/questions. And I can see all my existing users but no sign in is available.
I see a lot of Url redirects not working because of reverse, like Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. In my backend database all the tables are looking fine. But users are not integrated with askbot, also there is AttributeError with context_processor.py.
How to allow my existing and future users, who are authenticated by my existing django project use askbot seamlessly?
How does the askbot admin integrates with my existing admin site?
Can we convert Jinja2 template to Django tempalte?
This is my template context tuple
TEMPLATE_CONTEXT_PROCESSORS = (
#askbot
#'django.contrib.auth.context_processors.auth',
'django.core.context_processors.request',
#"allauth.context_processors.allauth",
#"allauth.account.context_processors.account",
'askbot.context.application_settings',
#'django.core.context_processors.i18n',
'askbot.user_messages.context_processors.user_messages',#must be before auth
'django.contrib.auth.context_processors.auth', #this is required for admin
'django.core.context_processors.csrf', #necessary for csrf protection
###############askbot ended###########
#"django.contrib.auth.context_processors.auth",
"django.core.context_processors.media",
'django.core.context_processors.static',
#"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
"apps.common.utils.context_processors.app_wide_vars",
"apps.common.context_processors.feedback_questions",
"allauth.context_processors.allauth",
"allauth.account.context_processors.account",
#"allauth.socialaccount.context_processors.socialaccount",
#'cms.context_processors.media',
'sekizai.context_processors.sekizai',
#'admintools_bootstrap.context_processors.site',
)

Django admin DoesNotExist at /admin/

I have some problems with Django admin.
after syncdb, the result is:
Creating tables ...
Installing custom SQL ...
Installing indexes ...
No fixtures found.
What does this mean?
Anyway, when I visit the website admin panel http://www.example.com/admin/, I receive this message:
DoesNotExist at /admin/
Site matching query does not exist.
setting.py contains:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
)
ur.py contains:
from django.conf.urls.defaults import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'rshd.views.home', name='home'),
# url(r'^rshd/', include('rshd.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
You don't really need the sites framework if you only run one site from the project, so the easiest fix would be to remove the following item from your INSTALLED_APPS and the error should go away:
'django.contrib.sites'
You can also re-create the missing Site object from shell. Run python manage.py shell and then:
from django.contrib.sites.models import Site
Site.objects.create(pk=1, domain='www.example.com', name='example.com')
You can fix this error if you are using django.contrib.sites without removing it by changing SITE_ID = 1 value in settings.py file.
It is happen to me when I changed domain name on my server, I deleted old domain name from http://mynewdomainname.com/admin/sites/site/ manually, and the old domain record in database has id = 1, also I added new domain name mynewdomainname.com and it is id was id = 2,
I just changed to SITE_ID = 2 and the error gone SITE_ID refers to current "pk" of active domain name you use as default.
In code:
>>> from django.contrib.sites.models import Site
>>> # get_current() came from SiteManager class manager,
>>> # see site-packages/django/contrib/sites/models.py
>>> current_site = Site.objects.get_current()
>>> print(current_site.pk)
2
>>> print(current_site.domain)
'http://mynewdomainname.com'
this happen after settings.py changed
SITE_ID = 2
Be careful about current domain id in django sites app.
The same problem also suddenly came to me, and you know there're many solutions. However, what's the reason of this sudden problem?
After dig in deeply, I found the reason is that, we ignored a step in the first syncdb action.
When you have your first syncdb, django will ask you to create a default account, if you don't input in this interactive show, that site object would not be created automatically.
So be careful of this. I'm using django 1.3.1, don't know whether the latest version has resolved this issue.
Since the above comments are pretty old and the syncdb command doesn't exist, and I don't want to remove django.contrib.sites, here's what worked for me:
Increment SITE_ID. I had SITE_ID = 1, changed it to SITE_ID = 2 and everything worked again.
Add SITE_ID = 1 in your settings.py
just fixed the issue by an another way:
I use PostgreSQL and Django 1.45...
as i removed the www.example.com Site and added a new www.xxx.com Site it was added as ID=2
'cause PostgreSQL doesn't go back in the ID numbers and the login and logout Django-Sites are somehow bound only to the ID=1 Site in your DB...
I went to my PostgreSQL DB and changed the ID of www.xxx.com to 1 and then I was able to see the login and logout Site again :)
btw. [yes, you just can remove the django.contrib.sites from your settings.py if you don't need it ^^ (but I haven't tried this one out in my case, with the ID number problem)]
hope it will work for further users! ;)
Yes change the SITE_IT=1 to SITE_ID=2 and everything is ok
Yes, the solution mentioned at the top can be (part of) the solution.
I've noticed however, that not only including django.contrib.sites without configuration can cause that problem, also including any site of
allauth (pip install django-allauth) might cause this problem if said package is not configured correctly.
(And allauth is as far as I've seen not configured correctly by default...)
Another thing you can do is simple if you get some error or just want to change site.
Download sqlitebrowser
open your sqlite.db
search for django_sites
change domain name and display name to whatever you want
Check your Window task manager and make sure that there is 1 process name 'python.exe' is running. If there are many, delete all of them then restart the server. This solution works for me.

How do I stop django from syncing certain tables when I do syncdb?

Whenever I run the syncdb command, I'm getting a lot of auth tables created but I'm not including the admin or auth packages. Here are the tables it is creating on its own:
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
I don't need these tables. In my settings.py file, I have commented out the AuthenticationMiddleware, MessageMiddleware and all apps except for django.contrib.sessions and my own personal apps. Is there a setting somewhere that I'm missing so that these tables aren't created?
Here are my INSTALLED_APPS
INSTALLED_APPS = (
'deanproxy.globaltags',
'deanproxy.blog',
'deanproxy.auth',
'deanproxy.twitter',
# 'django.contrib.auth',
# 'django.contrib.contenttypes',
'django.contrib.sessions',
# 'django.contrib.sites',
# 'django.contrib.messages',
#'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
EDIT: I Just realized that if I comment out my own app 'deanproxy.auth', that all of these tables are not created. However, my auth app isn't including any of the django auth stuff and it's a very, very simple auth system (just e-mail and password). It appears Django may be getting confused by the name of it...
I found the cause. I had an app called 'auth' which was a very simple auth system and nowhere near as involved as the django auth app. It appears that django was including all of these tables whenever I added 'deanproxy.auth' to my INSTALLED_APPS. Whenever I renamed this app to something else, these tables were not being included anymore. I'm going to try to track down why it does this... however, if anyone else has this issue, just name your app to something other than auth. Even though you're including it from your app, it still thinks it's the django auth system...

Should I remove 'django.contrib.comments' from my installed apps when I modify it by subclassing?

I'm customizing django comments.
According to the docs you'll need to add your customized app to INSTALLED_APPS in settings.py, and set COMMENTS_APP to your app name.
INSTALLED_APPS = [
...
'my_comment_app',
...
]
COMMENTS_APP = 'my_comment_app'
Should I also remove 'django.contrib.comments' from INSTALLED_APPS?
If you are only extending contrib.comments not replacing it, you shouldn't remove it from installed apps since, for example, most of the templatetags you need are in that application.
In order for Django to find the templates, templatetags and so on app must be in the installed apps.