2012-03-17 12 views
0

を動作しません。 /project_dir/html/mt.htmlファイルからロードされます。 しかし、それは次のエラーで失敗します。同じ時間でGAEテンプレートは、私は私のsettins.pyに次のコードを持っている

Traceback (most recent call last): 
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 701, in __call__ 
handler.get(*groups) 
File "D:\ap\pz4\pz4\main.py", line 33, in get 
x8= template.render(fn, {'some_content':blabla,}) 
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\template.py", line 91, in render 
t = _load_user_django(template_path, debug) 
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\template.py", line 113, in _load_user_django 
template = django.template.loader.get_template(file_name) 
File "C:\Program Files (x86)\Google\google_appengine\lib\django_1_3\django\template\loader.py", line 157, in get_template 
template, origin = find_template(template_name) 
File "C:\Program Files (x86)\Google\google_appengine\lib\django_1_3\django\template\loader.py", line 138, in find_template 
raise TemplateDoesNotExist(name) 
TemplateDoesNotExist: mt.html 

私は直接フォルダ定義を使用して、それを呼び出したとき、それは、正常に動作します:

r = template.render(os.path.join(os.path.dirname(__file__),'html/mt.html').replace("\\","/"),{'some_content':blabla,}) 

GAEは、1.6.3(ローカル)で、 djangoのバージョン(use_library( 'django'、 'xxx')を使用)は0.96,1.2,1.3でチェックされ、結果は同じです。

私は間違っていますか? DjangoはAPP_NAME /テンプレート/ APP_NAME/template.htmlでテンプレート(ええ、APP_NAMEが繰り返さ)

を探し、デフォルトで

答えて

0

は、それはあなたの場合のように、それはproject_dir/HTML /テンプレートを探します探しますproject_dir/template.html、project_dirがあなたのdjangoアプリ名と同じであると仮定します。

+0

私は、次のフォルダに "mt.html" を置く: app_root app_root/htmlの app_root/HTML/APP_NAME が、それはまだ動作していません。 – user1276220

+0

ドキュメントはあなた自身を助けるかもしれません。 https://docs.djangoproject。com/ja/dev/ref/templates/api/ 私は誤ったトラックにいるように見えますが、テンプレートでサブフォルダを使用していましたが、スタックトレースに指定された適切な場所にtemplate_pathまたはfile_nameのいずれかを出力する行を追加することで、デバッグが非常に簡単になります。 – dragonx

0

GAEでは、DjangoのTEMPLATE_DIRS施設は使用されていません。私はストレートthe templates docsのうち、基本的に次のことを、実行します。

この場合には、「index.htmlを」アプリのルートに住んでいる資源である、
path = os.path.join(os.path.dirname(__file__), 'index.html') 
self.response.out.write(template.render(path, template_values)) 

。テンプレートがアプリ内のディレクトリにある場合は、それに応じてos.path.join()を調整します。だから、

+0

それは明らかですが、それは私のためにも機能しますが、私は "拡張テンプレート"機能を使用する必要があり、すべてのテンプレートが同じ(ルート)フォルダに保存されている場合にのみ機能します。 しかし、私は深い(2-3レベル)のフォルダ構造を持ち、〜40のテンプレートを同じフォルダに保存したくないです。 – user1276220

+0

@ user1276220:関連する質問に関する私の答えは、あなたが 'extend'と' include'コールで相対パスを使うことを許すテクニックを持っています:http://stackoverflow.com/questions/5263623/templatedoesnotexist-on-python-app -engine-django-1-2-while-template-rendering-re –

1

、Webアプリケーションエンジンに問題: "_load_user_django" 方法(Cから:\プログラムファイル(x86の)\ Googleの\ google_appengine私のシステム上のGoogle \のAppEngine \のext \のWebアプリケーション\)オーバーライドユーザー

:それは次のエラーで失敗する "safe_join(template_dirの、テンプレート名)を" get_template_sources(filesystem.pyから)メソッドを呼び出すようにしようとすると、結果として

def _load_user_django(path, debug): 
    """Load the given template using the django found in third_party.""" 
    abspath = os.path.abspath(path) 

    if not debug: 
    template = template_cache.get(abspath, None) 
    else: 
    template = None 

    if not template: 
    directory, file_name = os.path.split(abspath) 
    new_settings = { 
     'TEMPLATE_DIRS': (directory,), 
     'TEMPLATE_DEBUG': debug, 
     'DEBUG': debug, 
     } 

    old_settings = _swap_settings(new_settings) 
    ... 

:TEMPLATE_DIRS変数を-defined

Traceback (most recent call last): 
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\admin\__init__.py", line 317, in post 
    exec(compiled_code, globals()) 
    File "<string>", line 3, in <module> 
    File "C:\Program Files (x86)\Google\google_appengine\lib\django_1_3\django\utils\_os.py", line 46, in safe_join 
    'path component (%s)' % (final_path, base_path)) 
ValueError: The joined path (x:\app_path\html\mt.html) is located outside of the base path component (x:\app_path\html\sub_templ_folder) 
0

チェックあなたのYAMLファイルに次の行を持っていない場合

- url: /templates 
    static_dir: templates 

あなたのパスは次のようであると仮定するとうまく動作します、それらの二行をあなたのコードを削除する場合:

path = os.path.join(os.path.dirname(__file__), 'templates/home.html') 
関連する問題