I am trying to make an application using django-allauth
; My Django
version is 1.11.5
.
I am trying to display the result on another template: facebook_personality_traits.html
Here is the code:
settings.py
SITE_ID = 1
LOGIN_REDIRECT_URL = 'facebook_personality_traits/'
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
'facebook': {
'SCOPE': ['email', 'user_posts'],
# 'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'METHOD': 'js_sdk',
'FIELDS': [
'id',
'email',
'name',
'first_name',
'last_name',
],
'EXCHANGE_TOKEN': True,
'VERIFIED_EMAIL': True
}
}
ACCOUNT_LOGOUT_ON_GET = True
views.py
def fb_personality_traits(request):
# logger.debug('FB Page Loaded')
return render(request, 'home/facebook_personality_traits.html')
urls.py
url(r'^facebook_personality-traits/$', views.fb_personality_traits, name="fb_personality_traits"),
facebook_personality_traits.html
<html>
<body>
Welcome back {{ user.first_name }} {{ user.last_name}}
<a href="/">Home</a>
</body>
</html>
But I could able to make it run effectively. I guess there is some issue where I have declared the url for the site. Here is the snapshot of the error:
Kindly suggest me the missed part.
It seems that you are using different urls.py for your apps. However you placed your url in to main urls.py.
url(r'^facebook_personality-traits/&', views.fb_personality_traits, name="fb_personality_traits"),
put this line to your apps urls.py where you put facebook_callback
url like this:
url(r'^login/token/facebook_personality_traits/$', views.fb_personality_traits, name="fb_personality_traits"),
BTW you have excessive & char at the end of your url, I guess you would like to put $ sign which represents end of line in regex.
EDIT 1:
My first impression about the problem was you were not putting the url in the right place but as far as i see, the redirection is done from a page under this path /accounts/facebook/login/token/
. Since there is no preceding /
at your redirect url in settings.py
it causes relative redirection.
Fix your url as following:
url(r'^facebook_personality_traits/$', views.fb_personality_traits, name="fb_personality_traits"),
In your settins.py you have set redirect url like below:
LOGIN_REDIRECT_URL = 'facebook_personality_traits/'
Since this is relative url, it goes to the url /accounts/facebook/login/token/facebook_personality_traits/
. Put a slash /
at the beginning of LOGIN_REDIRECT_URL
than your problem will be solved.
LOGIN_REDIRECT_URL = '/facebook_personality_traits/'