File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -116,18 +116,22 @@ template = t"Hello, {friend}!" # 😊
116
116
117
117
```` md magic-move
118
118
```python314
119
+ name = "world"
119
120
type(f"Hello, {name}!")
120
121
```
121
122
```python314
123
+ name = "world"
122
124
type(f"Hello, {name}!")
123
125
# <class 'str'>
124
126
```
125
127
```python314
128
+ name = "world"
126
129
type(f"Hello, {name}!")
127
130
# <class 'str'>
128
131
type(t"Hello, {name}!")
129
132
```
130
133
```python314
134
+ name = "world"
131
135
type(f"Hello, {name}!")
132
136
# <class 'str'>
133
137
type(t"Hello, {name}!")
@@ -359,6 +363,19 @@ for item in template:
359
363
```python314
360
364
name = "world"
361
365
template = t"<div>{name}</div>"
366
+ for item in template:
367
+ if isinstance(item, str):
368
+ print("static:", item)
369
+ else:
370
+ # `item` is a `string.templatelib.Interpolation`
371
+ print("dynamic:", item.value)
372
+ # static: <div>
373
+ # dynamic: world
374
+ # static: </div>
375
+ ```
376
+ ```python314
377
+ name = "world"
378
+ template = t"<div>{name}</div>"
362
379
parts = []
363
380
for item in template:
364
381
if isinstance(item, str):
@@ -549,7 +566,7 @@ def user_details(user: User, attribs: dict | None = None) -> Template:
549
566
def user_page(uid: str):
550
567
user = get_user_from_db(uid)
551
568
attribs = {"id": uid, "class": ["user", "active"]}
552
- return html(user_details(user, attribs)) # 🪄
569
+ return html(user_details(user, attribs)) # 🪄🪄🪄🪄🪄🪄 🪄
553
570
```
554
571
````
555
572
</div >
You can’t perform that action at this time.
0 commit comments