質問

I'm trying to deploy my webapp to Webfaction, the basic example is working correctly, I got a TemplateNotFound in a template that extends a basic template using Jinja2. Here is my project tree:

/webapps
    /myapp
        development.ini
        production.ini
        /bin
    /theapp
        /Project
          setup.py
          /project
              __init__.py
              views.py
              /templates
                  base.jinja2
                  home.jinja2
              /static

_init_.py

config.include('pyramid_jinja2')
config.add_jinja2_search_path("templates")

home.jinja2

{% extends "templates/base.jinja2" %}

To be more clear, the project works locally I know it's something with the template path, I'm not sure how to set it, I tried many different ways, anyways this is the traceback:

  File "..webapps/myapp/myapp/Project/project/templates/home.jinja2", line 1, in top-level template code
    {% extends "templates/base.jinja2" %}
  File "..webapps/myapp/lib/python2.7/site-packages/pyramid_jinja2-1.8-py2.7.egg/pyramid_jinja2/__init__.py", line 193, in get_source
    raise TemplateNotFound(name=ex.name, message=message)
TemplateNotFound: templates/base.jinja2; asset=..webapps/myapp/lib/python2.7/site-packages/Project-0.0-py2.7.egg/project/templates/base.jinja2; searchpath=['..webapps/myapp/lib/python2.7/site-packages/Project-0.0-py2.7.egg/project/templates']

Please help me set the correct path to templates, if that is my mistake.

役に立ちましたか?

解決

Since the search path is '..webapps/myapp/lib/python2.7/site-packages/Project-0.0-py2.7.egg/project/templates', that tells me you installed your application as an egg using python setup.py install. By far the most common pitfall of distributing your app in this way is that it requires a MANIFEST.in file when packaging your application in order for it to include static assets. python setup.py develop runs the application out of the directory instead, and does not suffer from that problem. I expect that if you unzip your egg file you will not find your templates inside.

他のヒント

Try add in file MANIFEST.in the extesion files.

recursive-include project *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml *.jinja2
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top