Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/_ext/djangodocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from docutils import nodes
from docutils.parsers.rst import Directive
from docutils.statemachine import ViewList
from github_links import get_branch
from sphinx import addnodes
from sphinx import version_info as sphinx_version
from sphinx.directives.code import CodeBlock
from sphinx.domains.std import Cmdoption
from sphinx.util import logging
from sphinx.util.nodes import split_explicit_title
from sphinx.writers.html import HTMLTranslator

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -62,6 +64,7 @@ def setup(app):
app.add_directive("console", ConsoleDirective)
app.connect("html-page-context", html_page_context_hook)
app.add_role("default-role-error", default_role_error)
app.add_role("sourcefile", sourcefile)
return {"parallel_read_safe": True}


Expand Down Expand Up @@ -372,3 +375,34 @@ def default_role_error(
)
logger.warning(msg, location=(inliner.document.current_source, lineno))
return [nodes.Text(text)], []


def sourcefile(
name,
rawtext,
text,
lineno,
inliner,
options=None,
content=None,
):
options = options or {}

_, title, target = split_explicit_title(text)

env = inliner.document.settings.env
branch = get_branch(
version=env.config.version,
next_version=env.config.django_next_version,
)
url = f"https://github.com/django/django/blob/{branch}/{target}"

literal = nodes.literal(title, title)
reference = nodes.reference(
rawtext,
"",
literal,
refuri=url,
**options,
)
return [reference], []
34 changes: 23 additions & 11 deletions docs/ref/forms/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ The template used to render a field's ``<label>``, used when calling
form by overriding this attribute or more generally by overriding the default
template, see also :ref:`overriding-built-in-form-templates`.

By default this is :sourcefile:`'django/forms/label.html'
<django/forms/templates/django/forms/label.html>`.

Output styles
-------------

Expand All @@ -673,7 +676,9 @@ template name.

.. attribute:: Form.template_name_div

The template used by ``as_div()``. Default: ``'django/forms/div.html'``.
The template used by ``as_div()``. Default:
:sourcefile:`'django/forms/div.html'
<django/forms/templates/django/forms/div.html>`.

.. method:: Form.as_div()

Expand Down Expand Up @@ -711,7 +716,8 @@ The template used by ``as_div()``. Default: ``'django/forms/div.html'``.

.. attribute:: Form.template_name_p

The template used by ``as_p()``. Default: ``'django/forms/p.html'``.
The template used by ``as_p()``. Default: :sourcefile:`'django/forms/p.html'
<django/forms/templates/django/forms/p.html>`.

.. method:: Form.as_p()

Expand All @@ -737,7 +743,8 @@ containing one field:

.. attribute:: Form.template_name_ul

The template used by ``as_ul()``. Default: ``'django/forms/ul.html'``.
The template used by ``as_ul()``. Default: :sourcefile:`'django/forms/ul.html'
<django/forms/templates/django/forms/ul.html>`.

.. method:: Form.as_ul()

Expand All @@ -764,7 +771,9 @@ you can specify any HTML attributes on the ``<ul>`` for flexibility:

.. attribute:: Form.template_name_table

The template used by ``as_table()``. Default: ``'django/forms/table.html'``.
The template used by ``as_table()``. Default:
:sourcefile:`'django/forms/table.html'
<django/forms/templates/django/forms/table.html>`.

.. method:: Form.as_table()

Expand Down Expand Up @@ -1086,21 +1095,24 @@ Customizing the error list format

The name of the template used when calling ``__str__`` or
:meth:`render`. By default this is
``'django/forms/errors/list/default.html'`` which is a proxy for the
``'ul.html'`` template.
:sourcefile:`'django/forms/errors/list/default.html'
<django/forms/templates/django/forms/errors/list/default.html>`,
which is a proxy for the ``'ul.html'`` template.

.. attribute:: template_name_text

The name of the template used when calling :meth:`.as_text`. By default
this is ``'django/forms/errors/list/text.html'``. This template renders
the errors as a list of bullet points.
this is :sourcefile:`'django/forms/errors/list/text.txt'
<django/forms/templates/django/forms/errors/list/text.txt>`. This
template renders the errors as a list of bullet points.

.. attribute:: template_name_ul

The name of the template used when calling :meth:`.as_ul`. By default
this is ``'django/forms/errors/list/ul.html'``. This template renders
the errors in ``<li>`` tags with a wrapping ``<ul>`` with the CSS
classes as defined by :attr:`.error_class`.
this is :sourcefile:`'django/forms/errors/list/ul.html'
<django/forms/templates/django/forms/errors/list/ul.html>`. This
template renders the errors in ``<li>`` tags with a wrapping ``<ul>``
with the CSS classes as defined by :attr:`.error_class`.

.. method:: get_context()

Expand Down
7 changes: 4 additions & 3 deletions docs/ref/forms/fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,10 @@ be ignored in favor of the value from the form's initial data.

The ``template_name`` argument allows a custom template to be used when the
field is rendered with :meth:`~django.forms.BoundField.as_field_group`. By
default this value is set to ``"django/forms/field.html"``. Can be changed per
field by overriding this attribute or more generally by overriding the default
template, see also :ref:`overriding-built-in-field-templates`.
default this value is set to :sourcefile:`"django/forms/field.html"
<django/forms/templates/django/forms/field.html>`. Can be changed per field by
overriding this attribute or more generally by overriding the default template,
see also :ref:`overriding-built-in-field-templates`.

``bound_field_class``
---------------------
Expand Down
18 changes: 11 additions & 7 deletions docs/ref/forms/renderers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ should return a rendered template (as a string) or raise

The default name of the template to use to render a form.

Defaults to ``"django/forms/div.html"`` template.
Defaults to the :sourcefile:`"django/forms/div.html"
<django/forms/templates/django/forms/div.html>` template.

.. attribute:: formset_template_name

The default name of the template to use to render a formset.

Defaults to ``"django/forms/formsets/div.html"`` template.
Defaults to the :sourcefile:`"django/forms/formsets/div.html"
<django/forms/templates/django/forms/formsets/div.html>` template.

.. attribute:: field_template_name

The default name of the template used to render a ``BoundField``.

Defaults to ``"django/forms/field.html"``
Defaults to :sourcefile:`"django/forms/field.html"
<django/forms/templates/django/forms/field.html>`.

.. attribute:: bound_field_class

Expand Down Expand Up @@ -101,7 +104,7 @@ This renderer uses a standalone
:class:`~django.template.backends.django.DjangoTemplates`
engine (unconnected to what you might have configured in the
:setting:`TEMPLATES` setting). It loads templates first from the built-in form
templates directory in :source:`django/forms/templates` and then from the
templates directory in :sourcefile:`django/forms/templates` and then from the
installed apps' templates directories using the :class:`app_directories
<django.template.loaders.app_directories.Loader>` loader.

Expand All @@ -116,7 +119,7 @@ If you want to render templates with customizations from your

This renderer is the same as the :class:`DjangoTemplates` renderer except that
it uses a :class:`~django.template.backends.jinja2.Jinja2` backend. Templates
for the built-in widgets are located in :source:`django/forms/jinja2` and
for the built-in widgets are located in :sourcefile:`django/forms/jinja2` and
installed apps can provide templates in a ``jinja2`` directory.

To use this backend, all the forms and widgets in your project and its
Expand Down Expand Up @@ -234,8 +237,9 @@ Overriding built-in widget templates
Each widget has a ``template_name`` attribute with a value such as
``input.html``. Built-in widget templates are stored in the
``django/forms/widgets`` path. You can provide a custom template for
``input.html`` by defining ``django/forms/widgets/input.html``, for example.
See :ref:`built-in widgets` for the name of each widget's template.
``input.html`` by defining
:sourcefile:`django/forms/templates/django/forms/widgets/input.html`, for
example. See :ref:`built-in widgets` for the name of each widget's template.

To override widget templates, you must use the :class:`TemplatesSetting`
renderer. Then overriding widget templates works :doc:`the same as
Expand Down
Loading
Loading