Skip to content

Commit 051e0f8

Browse files
committed
Fix imports of token types for Django 2.1
1 parent f2ddaba commit 051e0f8

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

django_babel/extract.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# -*- coding: utf-8 -*-
2-
from django.template.base import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
2+
try:
3+
from django.template.base import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
4+
except ImportError:
5+
try:
6+
# Django 1.8 moved most stuff to .base
7+
from django.template.base import (
8+
Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK,
9+
)
10+
except ImportError:
11+
# Django 2.1+
12+
from django.template.base import Lexer, TokenType
13+
14+
TOKEN_TEXT = TokenType.TEXT
15+
TOKEN_VAR = TokenType.VAR
16+
TOKEN_BLOCK = TokenType.BLOCK
17+
318
from django.utils.translation import trim_whitespace
419
from django.utils.encoding import smart_text
520

0 commit comments

Comments
 (0)