2011-09-29 16 views
0

私の独自のdjangoサーバ(自宅)に問題があり、djangoがテンプレートを見つけることができません。エラーコードdjan​​goが正しい場所を探しています(/ var/www/project/templates)しかし、何も起こらないDjangoテンプレートは本番サーバには存在しませんが、現在作業中です:8000

テンプレートは存在しませんしかしすべてのパスは問題ありません。

が、テストサーバーを使用して:8000すべての罰金ですが、私は知らないどのように病気の修正この

編集

テンプレートを取得するために、これは完璧です:

/var/www/agricultura/templates/forms/registro_form.html 

テンプレートのパス

import os 
TEMPLATE_DIRS = (
    os.path.join(os.path.abspath(os.path.dirname(__file__)),'templates'), 
) 

Template Loader Error: 
Django tried loading these templates, in this order: 
Using loader django.template.loaders.filesystem.Loader: 
/var/www/agricultura/templates/forms/registro_form.html (File does not exist) 
Using loader django.template.loaders.app_directories.Loader: 
/usr/local/lib/python2.6/dist-packages/admin_tools/theming/templates/forms/registro_form.html (File does not exist) 
/usr/local/lib/python2.6/dist-packages/admin_tools/menu/templates/forms/registro_form.html (File does not exist) 
/usr/local/lib/python2.6/dist-packages/admin_tools/dashboard/templates/forms/registro_form.html (File does not exist) 
/usr/local/lib/python2.6/dist-packages/django/contrib/admin/templates/forms/registro_form.html (File does not exist) 
Using loader django.template.loaders.eggs.Loader: 



Traceback: 
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response 
    111.       response = callback(request, *callback_args, **callback_kwargs) 
File "/var/www/agricultura/registro/views.py" in registro_view 
    71.       context_instance=RequestContext(request)) 
File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/__init__.py" in render_to_response 
    20.  return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) 
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in render_to_string 
    181.   t = get_template(template_name) 
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in get_template 
    157.  template, origin = find_template(template_name) 
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in find_template 
    138.  raise TemplateDoesNotExist(name) 

Exception Type: TemplateDoesNotExist at /registro/ 
Exception Value: forms/registro_form.html 

ありがとう

+0

修正済み:権限の問題:)権限が777 – Asinox

+0

ブラウザでアクセス可能なディレクトリにあなたのdjangoコード(テンプレートさえも)を置くべきではありません。 [私のコードはどこにあるべきですか?](https://docs.djangoproject.com/en/1.4/intro/tutorial01/) –

答えて

0

テンプレートにエラーがある可能性があります。設定でTEMPLATE_DEBUG = Trueを取得しましたか? TEMPLATE_DIRSも設定していますか?

は、サーバー上のpythonシェル経由でテンプレートをロードしてみてください。

https://docs.djangoproject.com/en/dev/ref/templates/api/#the-render-to-string-shortcut

./manage.py shell 
from django.template.loader import render_to_string 
rendered = render_to_string('my_template.html', { 'foo': 'bar' }) 

それがエラーをスローし、あなたにさらなる手掛かりを与えるかもしれません。

+0

返信用のpastylegsに感謝、よくTEMPLATE_DIRSはうまくいます – Asinox

+0

pastylegsに感謝しますが、何もニュースはありません: django.template.loader import render_to_string レンダリング= render_to_string( 'indexHome.html'、{'foo': 'bar'}) raise TemplateDoesNotExist(name) TemplateDoesNotExist:indexHome.html – Asinox

0

は、あなたの設定ファイルにこれを追加します。

def findMyWay(*relativeComponents): 
    return os.path.join(os.path.dirname(__file__), *relativeComponents).replace("\\","/") 

TEMPLATE_LOADERS = (
    "django.template.loaders.filesystem.Loader", 
    "django.template.loaders.app_directories.Loader", 
) 

TEMPLATE_DIRS = (
    findMyWay("templates"), 
) 

は私のために完全に正常に動作します。

0

些細なことですが、インストールされたアプリケーションに関連するアプリケーションを追加してテンプレートが見つかりませんというエラーが表示されることがあります。

関連する問題