Escape a value for use in a URL. The ``safe`` parameter determines the characters which should not be escaped by Python's quote() function. If not provided, use the default safe characters (but an empty string can be provided when *all* characters should be escaped).
(value, safe=None)
| 365 | @register.filter(is_safe=False) |
| 366 | @stringfilter |
| 367 | def urlencode(value, safe=None): |
| 368 | """ |
| 369 | Escape a value for use in a URL. |
| 370 | |
| 371 | The ``safe`` parameter determines the characters which should not be |
| 372 | escaped by Python's quote() function. If not provided, use the default safe |
| 373 | characters (but an empty string can be provided when *all* characters |
| 374 | should be escaped). |
| 375 | """ |
| 376 | kwargs = {} |
| 377 | if safe is not None: |
| 378 | kwargs["safe"] = safe |
| 379 | return quote(value, **kwargs) |
| 380 | |
| 381 | |
| 382 | @register.filter(is_safe=True, needs_autoescape=True) |