Есть 2 вопроса по django-allauth
1.Как переписать стандартный шаблон /accounts/logout/ или как его вовсе убрать
2.Как изменить переменную {{user}}
В общем, использую django-allauth для входа на сайт через соц. сеть ВК, с входом проблем нет, но при выходе хотелось бы чтобы сразу перекидывало на основную страницу без посредника /accounts/logout/.
Переменная {{user}} выдаёт id пользователя ВК, а хотелось бы имя или фамилию
Код:
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="{% static '/css/bootstrap.css' %}" type = 'text/css'>
<link type="text/css" rel="stylesheet" href="{% static '/css/bootstrap.min.css' %}">
<link type="text/css" rel="stylesheet" href="{% static '/css/bootstrap-social.css' %}">
</head>
<title>{{ title}}</title>
<body>
<hr>
{% if user %}
<a href = '/accounts/logout/'>Выйти({{ user}})</a>
{% else %}
<a href = '/accounts/vk/login/'>Войти</a>
{% endif %}
</body>
</html>
Код:
"""
Django settings for project_on_django3 project.
Generated by 'django-admin startproject' using Django 2.1.5.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2....ent/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '**'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'sitewitharticles',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.vk',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.twitter',
'allauth.socialaccount.providers.odnoklassniki',
'allauth.socialaccount.providers.instagram',
]
LOGIN_REDIRECT_URL = '/main/'
ACCOUNT_LOGOUT_REDIRECT_URL = '/main/'
MIDDLEWARE = [
'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 = 'project_on_django3.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'project_on_django3.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2....ngs/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '***',
'HOST': '127.0.0.1',
'PORT': '3306',
'USER': 'root',
'PASSWORD': '*****',
}
}
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',
)
# Password validation
# https://docs.djangoproject.com/en/2....ord-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'ru_RU'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2..../static-files/
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
SITE_ID = 3