mirror of
https://github.com/django-components/django-components.git
synced 2025-08-31 11:17:21 +00:00
Call parse_bits in django < 2.0 compatible way.
This commit is contained in:
parent
24369fce80
commit
b5eb6f4db1
1 changed files with 20 additions and 4 deletions
|
@ -1,3 +1,4 @@
|
|||
import django
|
||||
from django import template
|
||||
from django.template.base import Node, NodeList, TemplateSyntaxError, token_kwargs
|
||||
from django.template.library import parse_bits
|
||||
|
@ -16,6 +17,22 @@ except ImportError:
|
|||
VAR = TOKEN_VAR
|
||||
BLOCK = TOKEN_BLOCK
|
||||
|
||||
# Django < 2.0 compatibility
|
||||
if django.VERSION > (2, 0):
|
||||
PARSE_BITS_DEFAULTS = {
|
||||
"varargs": None,
|
||||
"varkw": [],
|
||||
"defaults": None,
|
||||
"kwonly": [],
|
||||
"kwonly_defaults": None,
|
||||
}
|
||||
else:
|
||||
PARSE_BITS_DEFAULTS = {
|
||||
"varargs": None,
|
||||
"varkw": [],
|
||||
"defaults": None,
|
||||
}
|
||||
|
||||
register = template.Library()
|
||||
|
||||
COMPONENT_CONTEXT_KEY = "component_context"
|
||||
|
@ -106,15 +123,14 @@ def do_component(parser, token):
|
|||
"""
|
||||
|
||||
bits = token.split_contents()
|
||||
|
||||
tag_args, tag_kwargs = parse_bits(
|
||||
parser=parser,
|
||||
bits=bits,
|
||||
params=["tag_name", "component_name"],
|
||||
varargs=None,
|
||||
varkw=[],
|
||||
defaults=None,
|
||||
takes_context=False,
|
||||
name="component_block"
|
||||
name="component_block",
|
||||
**PARSE_BITS_DEFAULTS
|
||||
)
|
||||
print(tag_args)
|
||||
tag_name = tag_args.pop(0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue