本文整理汇总了Python中django.contrib.auth.views.LoginView.as_view方法的典型用法代码示例。如果您正苦于以下问题:Python LoginView.as_view方法的具体用法?Python LoginView.as_view怎么用?Python LoginView.as_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.views.LoginView
的用法示例。
在下文中一共展示了LoginView.as_view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_login_csrf_rotate
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
def test_login_csrf_rotate(self):
"""
Makes sure that a login rotates the currently-used CSRF token.
"""
# Do a GET to establish a CSRF token
# TestClient isn't used here as we're testing middleware, essentially.
req = HttpRequest()
CsrfViewMiddleware().process_view(req, LoginView.as_view(), (), {})
# get_token() triggers CSRF token inclusion in the response
get_token(req)
resp = LoginView.as_view()(req)
resp2 = CsrfViewMiddleware().process_response(req, resp)
csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None)
token1 = csrf_cookie.coded_value
# Prepare the POST request
req = HttpRequest()
req.COOKIES[settings.CSRF_COOKIE_NAME] = token1
req.method = "POST"
req.POST = {'username': 'testclient', 'password': 'password', 'csrfmiddlewaretoken': token1}
# Use POST request to log in
SessionMiddleware().process_request(req)
CsrfViewMiddleware().process_view(req, LoginView.as_view(), (), {})
req.META["SERVER_NAME"] = "testserver" # Required to have redirect work in login view
req.META["SERVER_PORT"] = 80
resp = LoginView.as_view()(req)
resp2 = CsrfViewMiddleware().process_response(req, resp)
csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None)
token2 = csrf_cookie.coded_value
# Check the CSRF token switched
self.assertNotEqual(token1, token2)
示例2: login
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
def login(self):
"""
Return the login view.
"""
return LoginView.as_view(
template_name='zinnia/login.html'
)(self.request)
示例3: login
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
def login(self, request, extra_context=None):
"""
Displays the login form for the given HttpRequest.
"""
if request.method == 'GET' and self.has_permission(request):
# Already logged-in, redirect to admin index
index_path = reverse('admin:index', current_app=self.name)
return HttpResponseRedirect(index_path)
from django.contrib.auth.views import LoginView
# Since this module gets imported in the application's root package,
# it cannot import models from other applications at the module level,
# and django.contrib.admin.forms eventually imports User.
from django.contrib.admin.forms import AdminAuthenticationForm
context = dict(
self.each_context(request),
title=_('Log in'),
app_path=request.get_full_path(),
username=request.user.get_username(),
)
if (REDIRECT_FIELD_NAME not in request.GET and
REDIRECT_FIELD_NAME not in request.POST):
context[REDIRECT_FIELD_NAME] = reverse('admin:index', current_app=self.name)
context.update(extra_context or {})
defaults = {
'extra_context': context,
'authentication_form': self.login_form or AdminAuthenticationForm,
'template_name': self.login_template or 'admin/login.html',
}
request.current_app = self.name
return LoginView.as_view(**defaults)(request)
示例4: login
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
def login(request):
"""return the django.contrib.auth or the django-allauth login view"""
if settings.USE_ALL_AUTH:
# noinspection PyPackageRequirements
from allauth.account.views import login
return login(request)
return LoginView.as_view()(request)
示例5: smart_login
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
def smart_login(request):
pref_cas = request.COOKIES.get('prefer_cas', None)
use_cas = request.GET.get("force_cas", None)
next_url = request.GET.get("next", reverse('home'))
if request.user.is_authenticated:
return HttpResponseRedirect(next_url)
if pref_cas == "true" or use_cas == "true" or "ticket" in request.GET:
return cas_login(request, next_url)
else:
return LoginView.as_view(template_name='registration/login.html', authentication_form=forms.LoginForm)(request)
示例6: dispatch
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
login_defaults = {
'template_name': 'login.html',
'redirect_field_name': REDIRECT_FIELD_NAME,
'form_class': LoginForm,
'extra_context': {
'next_value': request.get_full_path(),
},
'redirect_authenticated_user': False,
}
return LoginView.as_view(**login_defaults)(request)
self.ensure_required_permission()
return super().dispatch(request, *args, **kwargs)
示例7: login
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
def login(request, extra_context=None):
"""
Display the login form.
"""
if request.method == 'GET' and request.user.is_active:
index_path = reverse(
'index', current_app=request.resolver_match.app_name)
return HttpResponseRedirect(index_path)
context = {
'title': _('Log in'),
'has_permission': request.user.is_active,
}
if REDIRECT_FIELD_NAME not in request.GET and REDIRECT_FIELD_NAME not in request.POST:
context[REDIRECT_FIELD_NAME] = reverse(
'index', current_app=request.resolver_match.app_name)
context.update(extra_context or {})
defaults = view_defaults(context, authentication_form=AuthenticationForm)
return LoginView.as_view(**defaults)(request)
示例8: path
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
from django.urls import path
from django.contrib.auth.views import LoginView, LogoutView
from django.views.generic import TemplateView
urlpatterns = [
path(r"", TemplateView.as_view(template_name="home.html"), name="home"),
path(r"login/", LoginView.as_view(), name="auth_login"),
path(r"logout/", LogoutView.as_view(template_name="logout.html"), name="auth_logout"),
]
示例9: path
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
from django.urls import path
from accounts.views import register, my_account, order_details, order_info
from django.contrib.auth.views import LoginView, LogoutView, PasswordChangeView
app_name = 'accounts'
urlpatterns = [
path('register/', register, {'template_name': 'registration/register.html'}, name='register'),
path('my_account/', my_account, {'template_name': 'registration/my_account.html'}, name='my_account'),
path('order_details/<order_id>/', order_details, {'template_name': 'registration/order_details.html'}, name='order_details'),
path('order_info/', order_info, {'template_name': 'registration/order_info.html'}, name='order_info'),
]
urlpatterns += [
path('login/', LoginView.as_view(), {'template_name': 'registration/login.html'}, name='login'),
path('logout/', LogoutView.as_view(), {'template_name': 'registration/logout.html'}, name='logout'),
path('password_change/', PasswordChangeView.as_view(), name='password_change')
]
示例10: reverse
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
from __future__ import unicode_literals, print_function, absolute_import
from django.conf import settings
from django.contrib.auth.views import LoginView, LogoutView
from django.urls import path, reverse
from django.views.generic import RedirectView
from .views import local_admin_login
app_name = "kirppuauth"
_urls = []
if not settings.KIRPPU_USE_SSO:
_urls.append(path('login/', LoginView.as_view(
template_name="kirppuauth/login.html",
extra_context={
"ask_pass": True,
"submit": lambda: reverse('kirppuauth:local_login'),
},
), name='local_login'))
_urls.append(path('profile/', RedirectView.as_view(pattern_name="home", permanent=False)))
_urls.append(path('logout/', LogoutView.as_view(next_page="home"), name='local_logout'))
if settings.KIRPPU_SU_AS_USER:
_urls.append(path('set_user', local_admin_login, name='local_admin_login'))
urlpatterns = _urls
示例11: path
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
"""
Definition of urls for $safeprojectname$.
"""
from datetime import datetime
from django.urls import path
from django.contrib import admin
from django.contrib.auth.views import LoginView, LogoutView
from app import forms, views
urlpatterns = [
path('', views.home, name='home'),
path('contact/', views.contact, name='contact'),
path('about/', views.about, name='about'),
path('login/',
LoginView.as_view
(
template_name='app/login.html',
authentication_form=forms.BootstrapAuthenticationForm,
extra_context=
{
'title': 'Log in',
'year' : datetime.now().year,
}
),
name='login'),
path('logout/', LogoutView.as_view(next_page='/'), name='logout'),
path('admin/', admin.site.urls),
]
示例12: include
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.contrib.auth.views import LoginView, LogoutView
from django.urls import include, path
from public.forms import UserAuthenticationForm
from . import views
# LoginView takes some work out of our hands.
# See https://devdocs.io/django~2.1/topics/auth/default#django.contrib.auth.views.LoginView
login_view = LoginView.as_view(
template_name='public/login.html',
redirect_authenticated_user=True,
authentication_form=UserAuthenticationForm,
)
# redirects to settings.LOGOUT_REDIRECT_URL
logout_view = LogoutView.as_view()
urlpatterns = [
path('', include('public.urls')),
path('login/', login_view, name='login'),
path('logout/', logout_view, name='logout'),
path('loginsuccess/', views.login_success, name='login-success'),
path('admin/', admin.site.urls),
path('students/', include('students.urls')),
path('teachers/', include('teachers.urls')),
path('users/', include('users.urls')),
示例13: url
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
name='details',
),
url(regex=r'^(?P<pk>\d+)/settings/avatar',
view=AvatarView.as_view(),
name='avatar',
),
url(regex=r'^(?P<pk>\d+)/settings/password',
view=PasswordView.as_view(),
name='password',
),
url(
regex=r'^login/$',
view=LoginView.as_view(redirect_authenticated_user=True, template_name='login.html'),
name='login'
),
url(
regex=r'^logout/$',
view=logout_then_login,
kwargs={'login_url': '/accounts/login'},
name='logout'
),
path('', include('django.contrib.auth.urls')),
path(
'reset/<uidb64>/<token>',
PasswordResetConfirmView.as_view(),
示例14: url
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
# -*- coding: utf-8 -*-
from django.conf.urls import url
from django.contrib.auth.views import LoginView, LogoutView, \
PasswordResetView, PasswordResetDoneView, PasswordResetConfirmView, PasswordResetCompleteView
urlpatterns = (
# login and logout url
url(r'^login/$', LoginView.as_view(template_name='login.html'), name='login'),
# or use logout with template 'logout.html'
url(r'^logout/$', LogoutView.as_view(), name='logout'),
# password reset urls
url(r'^password_reset/$',
PasswordResetView.as_view(template_name='password_reset.html'),
name='password_reset'),
url(r'^password_reset_done/$',
PasswordResetDoneView.as_view(template_name='password_reset_done.html'),
name='password_reset_done'),
url(r'^password_reset_confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
PasswordResetConfirmView.as_view(template_name='password_reset_confirm.html'),
name='password_reset_confirm'),
url(r'^password_reset_complete/$',
PasswordResetCompleteView.as_view(template_name='password_reset_complete.html'),
name='password_reset_complete'),
)
示例15: path
# 需要导入模块: from django.contrib.auth.views import LoginView [as 别名]
# 或者: from django.contrib.auth.views.LoginView import as_view [as 别名]
),
path(
"dashboard/requests/employees/<int:request_pk>/reject/",
views.RejectEmployeeRequest.as_view(),
name="reject-employee-request",
),
path(
"dashboard/requests/employees/<int:request_pk>/",
views.DetailEmployeeRequest.as_view(),
name="detail-employee-request",
),
path(
"dashboard/requests/contractors/<int:request_pk>/approve/",
views.ApproveContractorRequest.as_view(),
name="approve-contractor-request",
),
path(
"dashboard/requests/contractors/<int:request_pk>/reject/",
views.RejectContractorRequest.as_view(),
name="reject-contractor-request",
),
path(
"dashboard/requests/contractors/<int:request_pk>/",
views.DetailContractorRequest.as_view(),
name="detail-contractor-request",
),
path("admin/", admin.site.urls),
path("login", LoginView.as_view(), name="login"),
path("logout", LogoutView.as_view(), name="logout"),
]