Django: django-facebook redirects to /facebook/connect/ - django

I read all the documentation about django-facebook, and I'm still not understanding why after setup the settings.py, the registration redirects to a template on django-facebook.
settings.py
FACEBOOK_LOGIN_DEFAULT_REDIRECT = '/profile/'
FACEBOOK_REGISTRATION_BACKEND = 'django_facebook.registration_backends.UserenaBackend'
LOGIN_REDIRECT_URL = '/profile/'
AUTHENTICATION_BACKENDS = (
'userena.backends.UserenaAuthenticationBackend',
'django_facebook.auth_backends.FacebookBackend',
'django.contrib.auth.backends.ModelBackend',
'guardian.backends.ObjectPermissionBackend',
)
The template shouldn't be editable on templates folder at my app?
There is something I'm missing?
Thanks!

It's all about the template loader priority, I think. Try to list your custom app before the django-facebook in your settings INSTALLED_APPS and you should get the right template.

Related

Django: How to use a custom social-auth backend?

I have overridden the GoogleOAuth2 class in django social-auth.
Currently the new class is in views.py.
But I cannot find how to add it to AUTHENTICATION_BACKENDS in settings.py
I have tried like this:
AUTHENTICATION_BACKENDS = (
'_auth.backends.YouTubeOAuth2', <---------- new backend
'social_core.backends.google.GoogleOAuth2',
'social_core.backends.twitter.TwitterOAuth',
'social_core.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
And adjusted the template:
window.open('{% url 'social:begin' 'youtube' %}', '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
In the end of the Google auth process comes an error:
ModuleNotFoundError at /api/oauth/complete/google-oauth2/
No module named '_auth'

Django admin template override 'change_list' not working on Heroku

I have template files located app directories like %project%/%app%/templates, and have had no trouble with Heroku locating other templates files. I now have an admin template at %project%/%app%/templates/admin/%app%/%model%/change_list.html and when I am browsing the admin pages locally the template renders fine. When I try on Heroku my template is not showing up and just the default change_list.html is showing.
I have no other template issues and have tried putting the templates at the root level in %project%/templates/.
Here is my template config:
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader'
)
I am also using grappelli if that matters.
Anyone have an idea of what could be going on?
In order to load your own change-list template you have to add this to your admin model:
#admin.py
from django.contrib import admin
class AuthorAdmin(admin.ModelAdmin):
change_list_template = 'admin/author/change_list.html'
list_display = ('name','age',)
You will need to create the author/change_list.html under the templates directory. More information here in the official Django documentation page.

TemplateDoesNotExist Django Error

I am trying to build a login page form. In my urls.py, I have linked the file to the built in Django login view, and pass in the path to a template directory. I have login folder inside the template and login.html file inside the login folder.
(r'^login/$', 'django.contrib.auth.views.login', {
'template_name': 'login/login.html'
}),
In settings.py, I have provided the directory where my templates are being stored.
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__),'templates'),
)
When I run the runserver command, it shows TemplateDoesNotExist
Exception Type: TemplateDoesNotExist
Exception Value:login/login.html
For anyone experiencing the same problem, it turns out the template path was incorrect. I needed to use '../templates', instead of 'templates' in settings.py:
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__),'../templates'),
)
A better approach would be define your Directories in another settings file, to alleviate the need to use ugly relative path in your template dirs:
// _paths.py
SETTINGS_DIR = os.path.dirname(__file__)
// _templates.py
from settings/_paths.py import SETTINGS_DIR
TEMPLATE_DIRS = (
os.path.join(SETTINGS_DIR, 'templates'),
)
Adjust accordingly based on your folder structure.

Trouble loading django admin template

I am very new to Django and, following their tutorial, I am having issues loading a custom admin template (specifically, I am having trouble at the bottom of https://docs.djangoproject.com/en/1.4/intro/tutorial02/).
I have updated my TEMPLATE_DIRS so it looks like:
TEMPLATE_DIRS = (
'/Users/myname/Developer/Eclipse/templates/admin',
)
I have also tried:
TEMPLATE_DIRS = (
'/Users/myname/Developer/Eclipse/templates/admin/base_site.html',
)
The path for where I am storing this custom template follows:
"/Users/myname/Developer/Eclipse/templates/admin" (copy and pasted directly from file info)
Could someone point out what I am doing wrong? Thanks in advance.
Unless you don't use your admin folder for all the templates use this (I guess you want to overwrite admin templae. So admin folder should be subfolder of your template folder):
TEMPLATE_DIRS = (
'/Users/myname/Developer/Eclipse/templates/',
)
PROJECT_ROOT = os.path.dirname(__file__)
TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates"),)

Setting up django-allauth 404 error?

I am trying to get django-allauth to work for a project. In my Django project, lets call it yali, I did a git clone.
I then moved the folder /django-allauth/allauth to root /yali. and then deleted django-allauth and all the licenses, READMEs ...etc
According to documentation, there are three things I should do:
I should add this to settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
...
"allauth.context_processors.allauth",
"allauth.account.context_processors.account"
)
AUTHENTICATION_BACKENDS = (
...
"allauth.account.auth_backends.AuthenticationBackend",
)
INSTALLED_APPS = (
...
'emailconfirmation',
'uni_form',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.twitter',
'allauth.openid',
'allauth.facebook',
And then add this to urls.py
(r'^accounts/', include('allauth.urls')))
Doing so, gives me a 404 when navigating to http://localhost:8000/account
What am I missing here? The documentation is somewhat unclear here and even potentially wrong. It instructs to point urls.py to "accounts", while there is no "accounts" folder but "account"
The folder name has nothing to do with the url. The urls of your apps are defined in urls.py. You can put what you want, but you must use those same urls when navigating in the browser.
In your case, you must navigate to:
http://localhost:8000/accounts
If you have defined urls as:
(r'^anything/', include('allauth.urls')))
you should navigate to:
http://localhost:8000/anything