I'm used to php + twig, so I changed the template engine of pyramid 1.5 to jinja2

When I investigated what a template engine that can be written like twig with python, jinja seemed to be close to it, so I put it in a memo.

rewrite setup.py

Add jinja2 to requires.

setup.py


#Add the following
requires = [
    'pyramid_jinja2',
]

rewrite development.ini

Added to include under app.main. And added jinja2.directories.

development.ini


[app:main]
pyramid.include = 
    pyramid_debugtoolbar
    pyramid_tm
    pyramid_jinja2

#Myapp is the application name
jinja2.directories = myapp:templates

Run setup.py

Do the following to get jinja2

python setup.py develop

Rewrite init.py

Add various things to config.

__init__.py


def main(global_config, **settings):
    # config.scan()Added before
    config.include('pyramid_jinja2')
    config.add_renderer(".html", "pyramid_jinja2.renderer_factory")
    #myapp is the application name
    config.add_jinja2_search_path("myapp:templates")

    config.scan()

With this, if you call templates with the default extension of pt as html, you can write like twig!

Recommended Posts

I'm used to php + twig, so I changed the template engine of pyramid 1.5 to jinja2
I tried to summarize the frequently used implementation method of pytest-mock
I used the worldcup command to check the outcome of the World Cup.
The Python project template I think of.
I didn't understand the Resize of TensorFlow so I tried to summarize it visually.
I tried to touch the API of ebay
I'm tired of Python, so I tried to analyze the data with nehan (I want to go live even with corona sickness-Part 2)
I'm tired of Python, so I tried to analyze the data with nehan (I want to go live even with corona sickness-Part 1)
I want to customize the appearance of zabbix
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I tried to extract the text in the image file using Tesseract of the OCR engine
I used Python to find out about the role choices of the 51 "Yachts" in the world.
Template of python script to read the contents of the file
I want to grep the execution result of strace
I tried to summarize the basic form of GPLVM
The performance of PHP was better than I expected
How to use template engine in pyramid 1 file application
I want to install a package of Php Redis
I tried to visualize the spacha information of VTuber
I tried to erase the negative part of Meros
I tried to classify the voices of voice actors
I want to increase the security of ssh connections
I tried to summarize the string operations of Python
I want to see something beautiful, so I tried to visualize the function used for benchmarking the optimization function.
I made a function to crop the image of python openCV, so please use it.