LoginSignup
0
0

More than 3 years have passed since last update.

お手軽 Django template 動作確認 (Django 1.11)

Last updated at Posted at 2019-05-13

テンプレートファイルを作らず、文字列からテンプレートクラスを作って動作確認をしたい。

そんなときは、Django Shell を起動 (python manage.py shell) 下記のようにする。

from django.template import engines

template_str = """Hello, {{ name }}!
{{ val|default:"I'm a default string." }}"""

django_engine = engines['django']
template = django_engine.from_string(template_str)

print(template.render(context={'name': 'world', 'val': None}))

結果

Hello, world!
I'm a default string.

参考: https://docs.djangoproject.com/en/1.11/topics/templates/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0