Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
6c6eb8a6
Kaydet (Commit)
6c6eb8a6
authored
Agu 20, 2015
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #24914 -- Added docs for more auth mixin methods.
üst
01966bb2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
16 deletions
+43
-16
default.txt
docs/topics/auth/default.txt
+43
-16
No files found.
docs/topics/auth/default.txt
Dosyayı görüntüle @
6c6eb8a6
...
@@ -607,17 +607,25 @@ redirects to the login page::
...
@@ -607,17 +607,25 @@ redirects to the login page::
When using :doc:`class-based views </topics/class-based-views/index>`, you
When using :doc:`class-based views </topics/class-based-views/index>`, you
can use the ``UserPassesTestMixin`` to do this.
can use the ``UserPassesTestMixin`` to do this.
You have to override the ``test_func()`` method of the class to provide
.. method:: test_func()
the test that is performed. Furthermore, you can set any of the parameters
of :class:`~django.contrib.auth.mixins.AccessMixin` to customize the
handling of unauthorized users::
from django.contrib.auth.mixins import UserPassesTestMixin
You have to override the ``test_func()`` method of the class to
provide the test that is performed. Furthermore, you can set any of the
parameters of :class:`~django.contrib.auth.mixins.AccessMixin` to
customize the handling of unauthorized users::
class MyView(UserPassesTestMixin, View):
from django.contrib.auth.mixins import UserPassesTestMixin
def test_func(self):
class MyView(UserPassesTestMixin, View):
return self.request.user.email.endswith('@example.com')
def test_func(self):
return self.request.user.email.endswith('@example.com')
.. method:: get_test_func()
You can also override the ``get_test_func()`` method to have the mixin
use a differently named function for its checks (instead of
:meth:`test_func`).
.. admonition:: Stacking ``UserPassesTestMixin``
.. admonition:: Stacking ``UserPassesTestMixin``
...
@@ -741,20 +749,19 @@ user to the login page or issue an HTTP 403 Forbidden response.
...
@@ -741,20 +749,19 @@ user to the login page or issue an HTTP 403 Forbidden response.
.. attribute:: login_url
.. attribute:: login_url
The URL that users who don't pass the test will be redirected to.
Default return value for :meth:`get_login_url`. Defaults to ``None``
Defaults to :setting:`settings.LOGIN_URL <LOGIN_URL>`.
in which case :meth:`get_login_url` falls back to
:setting:`settings.LOGIN_URL <LOGIN_URL>`.
.. attribute:: permission_denied_message
.. attribute:: permission_denied_message
When ``raise_exception`` is ``True``, this attribute can be used to
Default return value for :meth:`get_permission_denied_message`.
control the error message passed to the error handler for display to
Defaults to an empty string.
the user. Defaults to an empty string.
.. attribute:: redirect_field_name
.. attribute:: redirect_field_name
The name of the query parameter that will contain the URL the user
Default return value for :meth:`get_redirect_field_name`. Defaults to
should be redirected to after a successful login. If you set this to
``"next"``.
``None``, a query parameter won't be added. Defaults to ``"next"``.
.. attribute:: raise_exception
.. attribute:: raise_exception
...
@@ -762,6 +769,26 @@ user to the login page or issue an HTTP 403 Forbidden response.
...
@@ -762,6 +769,26 @@ user to the login page or issue an HTTP 403 Forbidden response.
:class:`~django.core.exceptions.PermissionDenied` exception will be
:class:`~django.core.exceptions.PermissionDenied` exception will be
raised instead of the redirect. Defaults to ``False``.
raised instead of the redirect. Defaults to ``False``.
.. method:: get_login_url()
Returns the URL that users who don't pass the test will be redirected
to. Returns :attr:`login_url` if set, or :setting:`settings.LOGIN_URL
<LOGIN_URL>` otherwise.
.. method:: get_permission_denied_message()
When :attr:`raise_exception` is ``True``, this method can be used to
control the error message passed to the error handler for display to
the user. Returns the :attr:`permission_denied_message` attribute by
default.
.. method:: get_redirect_field_name()
Returns the name of the query parameter that will contain the URL the
user should be redirected to after a successful login. If you set this
to ``None``, a query parameter won't be added. Returns the
:attr:`redirect_field_name` attribute by default.
.. method:: handle_no_permission()
.. method:: handle_no_permission()
Depending on the value of ``raise_exception``, the method either raises
Depending on the value of ``raise_exception``, the method either raises
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment