0
0
mirror of https://github.com/django/django.git synced 2024-11-21 19:09:18 +01:00

Extend documentation

This commit is contained in:
Johannes Maron 2024-11-08 13:25:36 +01:00
parent 19b35b2a22
commit d847e3376e
No known key found for this signature in database
2 changed files with 17 additions and 2 deletions

View File

@ -72,11 +72,13 @@ class MediaAsset:
self.attributes = attributes
def __eq__(self, other):
# Compare the path only, to ensure performant comparison in Media.merge.
return (self.__class__ is other.__class__ and self.path == other.path) or (
isinstance(other, str) and self._path == other
)
def __hash__(self):
# Hash the path only, to ensure performant comparison in Media.merge.
return hash(self._path)
def __str__(self):

View File

@ -283,14 +283,27 @@ you to pass custom HTML attributes::
css = {
"all": [CSS("pretty.css", media="all", crossorigin="anonymous")],
}
js = [JS("animations.js", defer=True)]
js = [
JS(
"https://code.jquery.com/jquery-3.3.1.slim.min.js",
**{
"integrity"="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
"crossorigin"="anonymous",
"async": True,
},
),
]
If this Media definition were to be rendered, it would become the following HTML:
.. code-block:: html+django
<script src="https://static.example.com/animations.js" defer></script>
<link href="https://static.example.com/pretty.css" media="all" crossorigin="anonymous" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"
async>
</script>
..note:: The ``media`` attribute on the CSS-object overrides the dictionary key.