模板

提供了一组模板。这些模板的范围从Django Admin Site Alternative来管理使用您的应用程序作为提供商的应用程序,到错误和授权模板。

您可以覆盖位于中的默认模板 templates/oauth2_provider 文件夹并提供自定义布局。要覆盖这些模板,您只需创建一个名为 oauth2_provider 在您的Templates文件夹中,并在此文件夹中,添加一个与您试图覆盖的模板名称匹配的文件。

可用的模板包括:

base.html

如果你只是想要一个不同的外观,你可以只覆盖这个模板。要继承此模板,只需添加 {% extends "oauth2_provider/base.html" %} 在其他模板的第一行中。这就是使用默认模板所做的事情。

其中定义的块包括:

  • title 在HTML标题标记内;

  • css 在头部内部;

  • content 在身体里。

authorize.html

Authorize is rendered in AuthorizationView (authorize/).

向此模板传递以下上下文变量:

  • scopes - list 具有应用程序请求的作用域;

小心

看见 DEFAULT_SCOPES 以了解在未请求作用域时返回的内容。

  • scopes_descriptions - list 以及对所请求的范围的描述;

  • application -安 Application 对象

备注

如果您尚未创建自己的应用程序模型(请参阅 扩展应用程序模型 ),您将获得一个 AbstractApplication 对象。

  • client_id -传入URI,已验证。

  • redirect_uri -传入URI(可选),已验证。

备注

如果请求中未提供,则已设置默认设置(请参见 default_redirect_uri() )。

  • response_type -传入URI,已验证。

  • state -传入URI(可选)。

  • form -安 AllowForm 所有隐藏的字段都已用上面的值填充。

重要

一个额外的变量,名为 error 如果发生OAuth2异常,也将可用。此变量是一个 dict 使用 errordescription

示例(这是您可以在上找到的默认页面 templates/oauth2_provider/authorize.html )::

{% extends "oauth2_provider/base.html" %}

{% load i18n %}
{% block content %}
    <div class="block-center">
        {% if not error %}
            <form id="authorizationForm" method="post">
                <h3 class="block-center-heading">{% trans "Authorize" %} {{ application.name }}?</h3>
                {% csrf_token %}

                {% for field in form %}
                    {% if field.is_hidden %}
                        {{ field }}
                    {% endif %}
                {% endfor %}

                <p>{% trans "Application requires the following permissions" %}</p>
                <ul>
                    {% for scope in scopes_descriptions %}
                        <li>{{ scope }}</li>
                    {% endfor %}
                </ul>

                {{ form.errors }}
                {{ form.non_field_errors }}

                <div class="control-group">
                    <div class="controls">
                        <input type="submit" class="btn btn-large" value="Cancel"/>
                        <input type="submit" class="btn btn-large btn-primary" name="allow" value="Authorize"/>
                    </div>
                </div>
            </form>

        {% else %}
            <h2>Error: {{ error.error }}</h2>
            <p>{{ error.description }}</p>
        {% endif %}
    </div>
{% endblock %}

管理

管理模板是Django Admin站点的替代方案,用于管理应用程序。

应用

所有模板都会收到 Application 物体。

备注

如果您尚未创建自己的应用程序模型(请参阅 扩展应用程序模型 ),您将获得一个 AbstractApplication 对象。

application_list.html

Rendered in ApplicationList (applications/). This class inherits django.views.generic.edit.ListView.

向此模板传递以下模板上下文变量:

  • applications -a list 对于所有的应用程序,可能是 None

application_form.html

Rendered in ApplicationUpdate (applications/<pk>/update/). This class inherits django.views.generic.edit.UpdateView.

向此模板传递以下模板上下文变量:

  • application -- Application 对象。

  • form -a Form 具有以下字段:
    • name

    • client_id

    • client_secret

    • client_type

    • authorization_grant_type

    • redirect_uris

    • post_logout_redirect_uris

小心

在默认实现中,此模板由 application_registration_form.html 。如果只覆盖此模板,请确保提供相同的块。

application_registration_form.html

Rendered in ApplicationRegistration (applications/register/). This class inherits django.views.generic.edit.CreateView.

向此模板传递以下模板上下文变量:

  • form -a Form 具有以下字段:
    • name

    • client_id

    • client_secret

    • client_type

    • authorization_grant_type

    • redirect_uris

    • post_logout_redirect_uris

备注

在默认实现中,此模板扩展 application_form.html

application_detail.html

Rendered in ApplicationDetail (applications/<pk>/). This class inherits django.views.generic.edit.DetailView.

向此模板传递以下模板上下文变量:

application_confirm_delete.html

Rendered in ApplicationDelete (applications/<pk>/delete/). This class inherits django.views.generic.edit.DeleteView.

向此模板传递以下模板上下文变量:

重要

要成功覆盖此模板,您应该提供一个发布到相同URL的表单,例如: <form method="post" action="">

令牌

所有模板都会收到 AccessToken 物体。

Authorized-tokens.html

Rendered in AuthorizedTokensListView (authorized_tokens/). This class inherits django.views.generic.edit.ListView.

向此模板传递以下模板上下文变量:

  • authorized_tokens -a list 对于属于用户拥有的应用程序的所有令牌,可以是 None

重要

要成功覆盖此模板,您应该提供撤销令牌的链接,例如: <a href="{% url 'oauth2_provider:authorized-token-delete' authorized_token.pk %}">revoke</a>

Authorized-token-delete.html

Rendered in AuthorizedTokenDeleteView (authorized_tokens/<pk>/delete/). This class inherits django.views.generic.edit.DeleteView.

向此模板传递以下模板上下文变量:

重要

要成功覆盖此模板,您应该提供一个发布到相同URL的表单,例如: <form method="post" action="">