回答編集履歴
1
補足を追加
test
CHANGED
@@ -17,3 +17,35 @@
|
|
17
17
|
print(target_elem)
|
18
18
|
|
19
19
|
```
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
元のコードを活かしてフィルターにすると、
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```Python
|
28
|
+
|
29
|
+
from django import template
|
30
|
+
|
31
|
+
import re
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
register = template.Library()
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
@register.filter(name="youtube_embed_url")
|
42
|
+
|
43
|
+
def youtube_embed_url(content):
|
44
|
+
|
45
|
+
return re.sub(r'https://youtu.be/([a-zA-Z\d_-]+)',
|
46
|
+
|
47
|
+
r'<iframe width="560" height="315" src="https://www.youtube.com/embed/\1" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
|
48
|
+
|
49
|
+
content)
|
50
|
+
|
51
|
+
```
|