need to package jinja2 template for python

后端 未结 3 1063
北海茫月
北海茫月 2021-01-21 23:37

(UPDATE: I\'ve made a better question with a better answer here. I was going to delete this question, but some of the answers might prove useful to future searchers.)

M

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 23:51

    Maybe an issue is in PYTHONPATH . According to Python documantation https://docs.python.org/2.7/tutorial/modules.html#the-module-search-path it searches for modules in :

    • the directory containing the input script (or the current directory).
    • PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
    • the installation-dependent default.

    You can add some code to your application - printing sys.path variable to make sure your applcation's path is also there.

    import sys
    from jinja2 import Environment, PackageLoader # no prob, jinja2 correctly installed using pip
    print sys.path # printing your sys.path
    env = Environment(loader=PackageLoader('mypkg', 'template')) # causes server error
    

    If it's not You can add by

    sys.path.append(path_to_your_application) 
    

提交回复
热议问题