我无法在我的测试用例中导入自定义模板标记检查。如果我通过浏览器手动测试它就可以了。
from django.template import Template
class CheckTagTest(TestCase):
TEMPLATE = Template("""
{% load roles_extra %}
{% check /demo/view1/ POST %}This will appear,.{% endcheck %}
{% check /demo/view1/ GET %}This will not appear .{% endcheck %}"""
)
fixtures = ['test_check.json']
def test_tag_correct(self):
user = get_user_model().objects.get(username='admin')
rendered = self.TEMPLATE.render(Context({'user':user}))
roles_extra 不是有效的标记库,
File "C:\Python27\Lib\unittest\loader.py", line 91, in loadTestsFromName
module = __import__('.'.join(parts_copy))
File "<some_path>rolemanagement\roles\tests.py", line 40, in RegisterTest
class CheckTagTest(TestCase):
File "<some_path>rolemanagement\roles\tests.py", line 45, in CheckTagTest
{% check /demo/view1/ GET %}This will not appear .{% endcheck %}"""
File "<some_path>lib\site-packages\django-1.8-py2.7.egg\django\template\base.py", line 190, in __init__
self.nodelist = engine.compile_string(template_string, origin)
File "<some_path>lib\site-packages\django-1.8-py2.7.egg\django\template\engine.py", line 261, in compile_string
return parser.parse()
File "<some_path>lib\site-packages\django-1.8-py2.7.egg\django\template\base.py", line 341, in parse
compiled_result = compile_func(self, token)
File "<some_path>lib\site-packages\django-1.8-py2.7.egg\django\template\defaulttags.py", line 1159, in load
(taglib, e))
django.template.base.TemplateSyntaxError: 'roles_extra' is not a valid tag library: Template library roles_extra not found, tried django.templatetags.roles_extra,django.contrib.admin.templatetags.roles_extra,django.contrib.staticfiles.templatetags.roles_extra,django_messages.templatetags.roles_extra,rest_framework.templatetags.roles_extra,djangular.templatetags.roles_extra,django_extensions.templatetags.roles_extra
如何解决这个问题?