0

初めてアプリをherokuにデプロイしたばかりですが、ブラウズしようとするとTemplateDoesNotExistpython manage.py runserver. 私は見回して似たような問題を見てきましたが、これらの人は問題をどのように解決したかを説明していません.

Template Loader Error:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/templates/public/homepage.html (File does not exist)

Traceback:
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/app/f4l/live/views.py" in homepage
  156.  return render_to_response('public/homepage.html',context,context_instance=RequestContext(request))
File "/app/.heroku/python/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  169.         t = get_template(template_name)
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/loader.py" in get_template
  145.     template, origin = find_template(template_name)
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/loader.py" in find_template
  138.     raise TemplateDoesNotExist(name)

Exception Type: TemplateDoesNotExist at /
Exception Value: public/homepage.html

私のsettings.pyで

PROJECT_ROOT = os.path.join(os.path.dirname(__file__),'..')
SITE_ROOT = PROJECT_ROOT

#FIXTURE_DIRS = (os.path.join(PROJECT_DIR,  '../fixtures'),)
TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, '../templates'),)
STATICFILES_DIRS = (os.path.join(PROJECT_ROOT, '../static'), os.path.join(PROJECT_ROOT, '../media'), )
STATIC_ROOT = os.path.join(PROJECT_ROOT, '../sitestatic')
MEDIA_ROOT = os.path.join(PROJECT_ROOT, '../media')
MEDIA_URL = "/media/"
STATIC_URL = "/static/"

回答や読み物の提案は大歓迎です。

4

1 に答える 1

0

ドキュメントのガイドラインに従っていることを確認してください。TimD が指摘したように、静的ディレクトリとテンプレート ディレクトリは珍しいものです。私は DeployDjango.com (ここにあります) で推奨されている構造に似た構造を好みます。この構造では、各アプリに独自の静的ファイルとテンプレート ファイルのディレクトリがあります。何かのようなもの:

|--project_root
   |--apps
      |--my_app
         |--static
         |--templates
   |--manage.py
...

collectstaticドキュメントによると、そうすれば、コマンドは自動的にそれらを見つけます:

Put your static files somewhere that staticfiles will find them.
By default, this means within static/ subdirectories of apps in your
INSTALLED_APPS.

また、静的ファイルに関する簡単なガイドcollectstaticに従って、Heroku で正しく実行されていることを確認してください。

于 2013-03-23T16:39:24.030 に答える