Z
Z
zelsky2015-05-01 11:22:44
Django
zelsky, 2015-05-01 11:22:44

Authorization vkontakte Django?

Swears on HTML
Reverse for 'socialauth_begin' with arguments '(u'vk-oauth',)' and keyword arguments '{}' not found. pattern(s) tried: []
settings.py

"""
Django settings for Podil project.

Generated by 'django-admin startproject' using Django 1.8.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS

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/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '[email protected]*wshi5uh0r3p$(h&oc%z(w7pqe)[email protected]=4k(=ik0iy'

# 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',
    'endless_pagination',
    
    'social.apps.django_app.default',
    'abida',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'Podil.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',
                'social.apps.django_app.context_processors.backends',
                'social.apps.django_app.context_processors.login_redirect',
            ],
        },
    },
]

WSGI_APPLICATION = 'Podil.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'abida',                      # Or path to database file if using sqlite3.
        'USER': 'blast',                      # Not used with sqlite3.
        'PASSWORD': '12345',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
      
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

TEMPLATE_CONTEXT_PROCESSORS += (
    'django.core.context_processors.request',
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.core.context_processors.tz',
    'django.contrib.messages.context_processors.messages',
    'social.apps.django_app.context_processors.backends',
    'social.apps.django_app.context_processors.login_redirect',
)


AUTHENTICATION_BACKENDS = (
    'social.backends.vk.VKOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

VK_APP_ID = '490062*'
VK_API_SECRET = '************************'


SETTINGS_PATH = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'),
)

views.py
from django.shortcuts import render

# Create your views here.
from django.shortcuts import render_to_response, redirect, render
from django.contrib.auth import logout as auth_logout
from django.contrib.auth.decorators import login_required
# from django.template.context import RequestContext


def login(request):
    # context = RequestContext(request, {
    #     'request': request, 'user': request.user})
    # return render_to_response('login.html', context_instance=context)
    return render(request, 'login.html')


@login_required(login_url='/')
def home(request):
    return render_to_response('home.html')


def logout(request):
    auth_logout(request)
    return redirect('/')

urls.py
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    # Examples:
    # url(r'^$', 'Podil.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    url('', include('social.apps.django_app.urls', namespace='social')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', 'abida.views.login'),
    url(r'^home/$', 'abida.views.home'),
    url(r'^logout/$', 'abida.views.logout'),
]

login.html
{% if user and not user.is_anonymous %}
  <a>Hello, {{ user.get_full_name }}!</a>
  <br>
  <a href="/logout">Logout</a>
{% else %}
  <a href="{% url 'socialauth_begin' 'vk-oauth' %}">Auth Vk</a>
{% endif %}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Pinkevich, 2015-05-01
@zelsky

allauth
python-social-auth also writes to the user base

I
Igor Morozov, 2015-08-11
@Morozzzko

Interestingly, this question remains unanswered.
Judging by the modules, python-social-auth is used, which replaced django-social-auth.
This code uses a slightly different format for composing the link. {% url 'socialauth_begin' 'vk-oauth' %}
All the examples in the documentation use a slightly different format for composing the link, namely {% url 'social:begin' 'vk-oauth2' %}
The error is that it could not find a view that matches "socialauth_begin".
The config included URLs from python-social-auth. python-social-auth suggests using namespaces. What is it and why is it well described in the documentation .
The general view for creating "login" links in python-social-auth looks like this: {% url 'social:begin' 'auth_backend' %}. Will create a link to example.com/where_social.apps.django.urls/login/auth_backend/ are installed.
A list of possible backends can be found here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question