I've implemented authentication on my application using django_registration and django_registration email. Here is my code:
settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
#custom apps
'order',
'fiesta',
#3rd party apps
'south',
'jquery',
'djangoformsetjs',
# DEVELOPER TOOLS
'debug_toolbar',
#authentication apps
'registration',
'registration_email',
)
#DJANGO REGISTRATION SETTINGS
ACCOUNT_ACTIVATION_DAYS = 7 # one week activation window
AUTHENTICATION_BACKENDS = (
'registration_email.auth.EmailBackend',
)
LOGIN_REDIRECT_URL = '/'
urls.py
urlpatterns = patterns('',
url(r'^$', lambda x:HttpResponseRedirect("/fiesta/workspace/"), name="home"),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('registration_email.backends.default.urls')),
url(r'^fiesta/', include('fiesta.urls')),
)
The registration email is sent okay but when i click on the account activation link, here is the error i get:
Traceback:
File "/home/blaqx/.virtualenv/django5/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115.response = callback(request, *callback_args, **callback_kwargs)
File "/home/blaqx/.virtualenv/django5/lib/python2.7/site-packages/django/views/generic/base.py" in view
68.return self.dispatch(request, *args, **kwargs)
File "/home/blaqx/.virtualenv/django5/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
86.return handler(request, *args, **kwargs)
File "/home/blaqx/.virtualenv/django5/lib/python2.7/site-packages/registration/views.py" in get
126.success_url = self.get_success_url(request, activated_user)
Exception Type: TypeError at /accounts/activate/bf93e2619ad0b7419b34dc0284e172fae8ecafef/
Exception Value: 'str' object is not callable
In the error, I can see that during account activation, a reference is being made to django-registration instead of django-registration-email. I however don't know if this is the cause of the error and how to solve it. Any help will be greatly appreciated.
First you are using two packages for same purpose(i.e; sending the email activation), Here the packeges,
django-registration-email
django-registration
Select the one package from above. I choose django-registration, Here the doc https://django-registration.readthedocs.org.
And follow the code instructions,
settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
#custom apps
'order',
'fiesta',
#3rd party apps
'south',
'jquery',
'djangoformsetjs',
# DEVELOPER TOOLS
'debug_toolbar',
#authentication apps
'registration',
#'registration_email',
)
#DJANGO REGISTRATION SETTINGS
ACCOUNT_ACTIVATION_DAYS = 7 # one week activation window
#AUTHENTICATION_BACKENDS = (
#'registration_email.auth.EmailBackend',
#)
LOGIN_REDIRECT_URL = '/'
urls.py
urlpatterns = patterns('',
url(r'^$', lambda x:HttpResponseRedirect("/fiesta/workspace/"), name="home"),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^fiesta/', include('fiesta.urls')),
)
Related
I am studing the djanto multi-tenant package (https://github.com/django-tenants/django-tenants).
When i try to access the main page (landing page) at http://127.0.0.1:8000/, I got the following message:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Raised by: core.views.home
No tenant for hostname "127.0.0.1"
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to
False, and Django will display a standard 404 page.
How do I get the landing page to show correctly?
URL FILE
from core.views import home
urlpatterns = [
path('admin/', admin.site.urls),
path('', home, name='home'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
THE VIEW OF LANDINGPAGE
from django.shortcuts import render
def home(request):
return render(request, 'core/index.html')
PARTIAL SETTINGS FILES
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
SHARED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_tenants',
'customer',
'core', //landing page
]
TENANT_APPS = [
# The following Django contrib apps must be in TENANT_APPS
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
# your tenant-specific apps
'myclientapp',
]
INSTALLED_APPS = list(set(SHARED_APPS + TENANT_APPS))
Thank you very much!
The issue there is with the Django Tenants middleware. By default, django_tenants will show a Page 404 error if you go to a tenant that does not exist. You can change this behavior by over-modifying the middleware and having your own local copy or (the easiest solution) you can just provide a default case by adding SHOW_PUBLIC_IF_NO_TENANT_FOUND = True in your project's settings.py file. This will route to the public schema hence other url routes will work as they should.
when i add sitemap to my Django project i got this error ..
DoesNotExist at /sitemap.xml
Site matching query does not exist.
sitemap.py :
from django.contrib.sitemaps import Sitemap
from .models import Homepage
class DynamicSitemap(Sitemap):
changefreq = "monthly"
priority = 0.5
def items(self):
return Homepage.objects.all()
url.py :
from first_app.sitemaps import DynamicSitemap
from django.contrib.sitemaps.views import sitemap
sitemaps = {'dynamic': DynamicSitemap()}
urlpatterns = [
path('sitemap.xml', sitemap , {'sitemaps': sitemaps}, name='sitemaps'),
]
settings.py :
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sites',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tinymce',
'first_app',
'django.contrib.sitemaps',
]
any help and thanks
You can try to add SITE_ID = 1 above INSTALLED_APPS.
According to the answer here comment out the 'django.contrib.sites' in the settings.py file under INSTALLED_APPS solve this problem.
I am setting up django with multitenant architecture. I went through the https://django-tenant-schemas.readthedocs.io/en/latest/install.html
instruction and get to the point that have inital startup screen.
What I want to achieve is to enable admin module for each tenant.
my in settings.py I have following:
#Application definition
SHARED_APPS = (
'tenant_schemas', # mandatory, should always be before any django app
'customers', # you must list the app where your tenant model resides in
'django.contrib.contenttypes',
# everything below here is optional
)
TENANT_APPS = (
'django.contrib.contenttypes',
# your tenant-specific apps
# 'myapp.hotels',
# 'myapp.houses',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
)
INSTALLED_APPS = [
'tenant_schemas',
'customers',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
]
TENANT_MODEL = "customers.Client"
MIDDLEWARE = [
'tenant_schemas.middleware.TenantMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'sitemanager.urls'
PUBLIC_SCHEMA_URLCONF = 'sitemanager.urls_public'
when trying to open http://localhost:8000/admin getting error:
DoesNotExist at /admin/login/
Site matching query does not exist.
Request Method: GET
Request URL: http://localhost:8000/admin/login/?next=/admin/
Django Version: 2.1.2
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
my urls.py:
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
What am I missing in configuration?
Adding PUBLIC_SCHEMA_NAME = 'public' sort the problem.
I think django.contrib.sites should be in SHARED_APPS.
Kudos for using django-tenant-schema +1
Then to create a superuser :./manage.py tenant_command createsuperuser
Might be handy.
I'm using django-cookiecutter to bootstrap my project which will include api paths. Following the steps in Two Scoops of Django 1.11 to configure my urls to follow a similar pattern to this:
api/foo_app/ # GET, POST
api/foo_app/:uuid/ # GET, PUT, DELETE
api/bar_app/ # GET, POST
api/bar_app/:uuid/ # GET, PUT, DELETE
When I try to setup my project like this I'm getting the following error:
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'my_project.core.api_urls' from /Users/username/Development/my_project/my_project/core/api_urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
My current setup:
my_project.config.settings.base.py
ROOT_URLCONF = 'config.urls'
DJANGO_APPS = [
# Default Django apps:
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Useful template tags:
# 'django.contrib.humanize',
# Admin
'django.contrib.admin',
]
THIRD_PARTY_APPS = [
'crispy_forms', # Form layouts
'allauth', # registration
'allauth.account', # registration
'allauth.socialaccount', # registration
'rest_framework',
]
# Apps specific for this project go here.
LOCAL_APPS = [
# custom users app
'my_project.users.apps.UsersConfig',
'my_project.core.apps.CoreConfig',
]
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
my_project.config.urls.py
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import TemplateView
from django.views import defaults as default_views
urlpatterns = [
url(r'^users/', include('my_project.users.urls', namespace='users')),
url(r'^api/', include('my_project.core.api_urls', namespace='api')),
]
my_project.core.api_urls.urls
from django.conf.urls import url
from django.views.defaults import page_not_found
urlpattenrs = [
url(
regex=r'^users/$',
view=page_not_found,
),
]
The core app does not contain any models right now. It's just where I'm organizing all the URLs
"urlpattenrs" should be "urlpatterns" (in my_project.core.api_urls.urls) ;)
I am pretty new into django and fully noob into django-social-auth.
My settings.py code is this (From installed app to social_auth_config) :
DJANGO_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
)
THIED_PARTY_APPS = (
#'south',
'captcha',
'social_auth',
)
MY_APPS = (
'account',
'dashboard',
)
INSTALLED_APPS = DJANGO_APPS + THIED_PARTY_APPS + MY_APPS
#------------------------------------------------- Social auth -------------------
LOGIN_URL = 'account/login/'
LOGIN_REDIRECT_URL = 'dashboard/'
LOGIN_ERROR_URL = '/login/'
AUTHENTICATION_BACKENDS = (
'social_auth.backends.contrib.github.GithubBackend',
'django.contrib.auth.backends.ModelBackend',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"social_auth.context_processors.social_auth_by_type_backends",
"django.contrib.auth.context_processors.auth",
)
SOCIAL_AUTH_DEFAULT_USERNAME = 'nal_auth_user'
SOCIAL_AUTH_UID_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16
SOCIAL_AUTH_NONCE_SERVER_URL_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_SERVER_URL_LENGTH = 16
SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 16
SOCIAL_AUTH_ENABLED_BACKENDS = ('github',)
GITHUB_API_KEY = '2f1129e79efd4263bf88'
GITHUB_API_SECRET = '6f4cea73e6100d0a994fa5bfff44f7220432c87d'
In urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', 'website.views.index', name='index'),
url(r'auth/',include('social_auth.urls')),
url(r'account/',include('account.urls',namespace="account")),
url(r'dashboard/',include('dashboard.urls',namespace="dashboard")),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)
In account.models login page i have this to show login url..
Login with GitHub
But problem is when ever i click that link it gives me this error
WrongBackend at /auth/login/github/
Incorrect authentication service "github"
Request Method: GET
Request URL: http://127.0.0.1:8000/auth/login/github/
Django Version: 1.5.4
Exception Type: WrongBackend
Exception Value:
Incorrect authentication service "github"
I tried to use google and its gives me the same error except in github its google. I also tried similar questions in stackoverflow.
Please help me if you can :)
check the version of the library of django_sociao_auth, as "THIS LIBRARY IS DEPRECATED IN FAVOR OF python-social-auth. RIGHT NOW THIS LIBRARY DEPENDS DIRECTLY ON python-social-auth AND SHOULD BE CONSIDERED AS A MIGRATION STEP".
Also check if SETTINGS_KEY_NAME = 'GITHUB_APP_ID' SETTINGS_SECRET_NAME = 'GITHUB_API_SECRET' are in class GithubAuth
then try to add this
SOCIAL_AUTH_PIPELINE = (
'social_auth.backends.pipeline.social.social_auth_user',
'social_auth.backends.pipeline.associate.associate_by_email',
'social_auth.backends.pipeline.misc.save_status_to_session',
'social_auth.backends.pipeline.user.create_user',
'social_auth.backends.pipeline.social.associate_user',
'social_auth.backends.pipeline.social.load_extra_data',
'social_auth.backends.pipeline.user.update_user_details',
'social_auth.backends.pipeline.misc.save_status_to_session',
)