I wanted to redirect some urls in my django project.
So i tried using django redirects app.
In settings.py :-
SITE_ID=1
INSTALLED APPS = (
...
'django.contrib.sites',
'django.contrib.redirects',
...
)
MIDDLEWARE_CLASSES = (
...
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
)
I did syncdb and then added the redirect from admin. Nothing happens.
Is there anything i missed?
Related
Allauth Github is working without any problem, however, Twitter is not.
When clicking on https://0.0.0.0:9000/accounts/twitter/login/ nothing happens and yet there's no error. Everything is 200 ok.
I'm using SSL in dev environement using django-sslserver.
settings.py
INSTALLED_APPS = [
...
'django.contrib.sites', # new
'allauth', # new
'allauth.account', # new
'allauth.socialaccount', # new
'allauth.socialaccount.providers.github', # new
'allauth.socialaccount.providers.twitter', # new
'sslserver',
]
SOCIALACCOUNT_PROVIDERS = {'github': {}, 'twitter':{}}
AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
)
SITE_ID = 1
LOGIN_REDIRECT_URL = '/'
I use example.com in my hosts' file:
/etc/hosts
0.0.0.0 example.com
And in the Twitter app, I use these configurations:
This is the social app configuration:
And the site configuration:
Do you see any problem?
The callback URL (can and) should be https://127.0.0.1:9000/accounts/twitter/login/callback/
This is how I solved this problem.
I want to use the allauth django app.
I did everything described in this allauth tutorial: http://www.sarahhagstrom.com/2013/09/the-missing-django-allauth-tutorial/. I continues until "Now we can login using Django or Facebook" subpart.
After that I can't go to the address that is indicated in the tutorial: http://127.0.0.1:8000/accounts/login/
I want you to see the database that I have. its exatly like the tutorial indicates:
This is my setting.py file:
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
"/srv/http/proj04/proj/templates",
)
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
# `allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend"
)
TEMPLATE_CONTEXT_PROCESSORS = (
# Required by allauth template tags
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.request",
# allauth specific context processors
"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount",
)
LOGIN_REDIRECT_URL = '/'
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': ['email', 'publish_stream'],
'METHOD': 'oauth2' # instead of 'oauth2'
}
}
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',
'captcha',
'django.contrib.admin',
# Uncomment the next line to enable the admin:
# Uncomment the next line to enable admin documentation:
'allauth',
'allauth.account',
'allauth.socialaccount',
# ... include the providers you want to enable:
'allauth.socialaccount.providers.amazon',
'allauth.socialaccount.providers.dropbox',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.flickr',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.instagram',
'allauth.socialaccount.providers.linkedin',
'allauth.socialaccount.providers.linkedin_oauth2',
'allauth.socialaccount.providers.openid',
'allauth.socialaccount.providers.tumblr',
'allauth.socialaccount.providers.twitter',
'allauth.socialaccount.providers.vimeo',
'allauth.socialaccount.providers.vk',
# 'django.contrib.admindocs',
)
This is my url.py file:
....
admin.autodiscover()
urlpatterns = patterns('',
(r'^accounts/', include('allauth.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)),
)
urlpatterns += [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
I don;t know what to do next.
I tried
http://127.0.0.1:8000/accounts/login/
Only to get this exception:
DoesNotExist at /accounts/login/
Site matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/login/
Django Version: 1.6.5
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
Exception Location: /srv/http/proj04/lib/python3.4/site-packages/django/db/models/query.py in get, line 310
Python Executable: /srv/http/proj04/bin/python
Python Version: 3.4.1
...
or sometimes i get this exception ( i dont know why but these exception alternate):
ImproperlyConfigured at /accounts/login/
No Facebook app configured: please add a SocialApp using the Django admin
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/login/
Django Version: 1.6.5
Exception Type: ImproperlyConfigured
Exception Value:
No Facebook app configured: please add a SocialApp using the Django admin
Exception Location: /srv/http/proj04/lib/python3.4/site-packages/allauth/socialaccount/providers/facebook/provider.py in media_js, line 106
Python Executable: /srv/http/proj04/bin/python
Python Version: 3.4.1
What am I missing?
Thanks in advance.
You need to modify your allauth google settings in your app settings. Take a look at the docs to see what settings are avaliable.
http://django-allauth.readthedocs.org/en/latest/#google
You'll also need to change your installed apps to only include these allauth apps
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google'
Add "SITE_ID" in settings.py
django_site table must contain a row with the same value of id (by default equals to 1), as SITE_ID.
And in your SocialApplication table 'localhost:8000/admin/socialaccount/socialapp/' for different providers give this site ID and try to run again, it will work.
i saw some topic about my problem however i didn' t find the solution for it and i don' t know what i' m doing wrong.
Since this is a test system,
i delete my whole db
i run syncdb && migrate to have everything clear.
i set the SITE_ID to 1
i restart apache2 (well, not using development server at the moment)
in the admin -> Sites -> Sites section i set the example.com to mysub.mydomain.com (for both the display name and domain name)
in the admin -> Socialaccount -> Social apps section i add a new app:
provider: facebook
name: the same name than on developers.facebook.com
client id: App ID/API Key from developers.facebook.com
Key: stays None
Secret: App Secret from developers.facebook.com
Chosen sites: i move here the only one existing which is mysub.mydomain.com (on developers.facebook.com i' ve the same mysub.mydomain.com at App Domains)
in the settings.py file i' ve these relevant sections:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
INSTALLED_APPS = (...,
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
)
TEMPLATE_CONTEXT_PROCESSORS += ('common.context_processors.add_app_name',
'django.core.context_processors.request',
'allauth.account.context_processors.account',
'allauth.socialaccount.context_processors.socialaccount',)
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
SOCIALACCOUNT_PROVIDERS = \
{ 'facebook':
{ 'SCOPE': ['email'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'METHOD': 'oauth2',
'LOCALE_FUNC': lambda request: 'en_US',
}
}
to the urls.py: url(r'^accounts/', include('allauth.urls')),
. After all these (and apache2 restart) when i go to mysub.mydomain.com/accounts/login/ (i log out from admin at first) i got the same error than for example here:
Django-allauth No Facebook app configured: please add a SocialApp using the Django admin
. I don' t really know what else can be the problem but i' d be happy if someone could point me to the right direction or to tell me what else to check.
Thanks.
I'm experiencing an issue with Django and Django Auth. From time to time the login page will not allow users to login. When the user presses login (on the /admin login form OR any custom login form) the page simply refreshes. After debugging further it seems that it is creating a session and then expiring it (somehow). Has anyone experienced this type of behavior with Django Auth?
Thanks,
cory
I haven't had this problem.
But so, you should check your apps, middleware, and context processor specifications in your settings.py file. You'll want to be sure the following are in place (in addition to whatever else you need for your specific app):
MIDDLEWARE_CLASSES = (
# ...
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
# ...
)
TEMPLATE_CONTEXT_PROCESSORS = (
# ...
"django.core.context_processors.auth",
"django.core.context_processors.request",
# ...
)
INSTALLED_APPS = (
# ...
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.sites',
# ...
)
... make sure that's all good to go and see if your problem persists. Good luck.
My flatpages relevant options in the settings.py look like this:
MIDDLEWARE_CLASSES = (
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.flatpages',
'django.contrib.humanize',
'registration',
)
and in the Backend I added a flatpage with the url set to "/" and one with "/about/. When I call these pages, django shows a 404 error. All my flatpages have a unique template. The "Template Name" entries are looking like this: /flatpages/about.html. What did i miss?
I found it.
I forgot to set the SITE_ID in settings.py correctly.
Do you have a base/default template in place for your flatpages, too? It's easy to miss as they docs don't go into much detail.
Easiest fix is to add /flatpages/default.html to your known templates, basing default.html on the example in the docs.
Or you can point your flatpages to a specific, existing template with the additional options in the admin edit page for a flatpage.
The key statement is changing the SITE_ID in settings.py which
has nothing to do with flatpages - it is a problem that new users
run into when launching into the 'admin' and adding (say) '127..0.0.1' to
the sites menu ( an addition to the default 'example.com' )
In trying to get everything else right, it is easy to overlook
making SITE_ID = 2.
Make 'locahost' the default - get rid of the default tripwire.
Glad I came across this!
Bob