【问题标题】:Template doesn't exist on heroku, but does locally模板在 Heroku 上不存在,但在本地存在
【发布时间】:2014-09-10 18:43:09
【问题描述】:

所以我在本地测试了我的项目,一切似乎都很完美。

虽然,当我将我的项目推送到我的 heroku 服务器时,除了一个链接之外的所有内容似乎都不起作用。请求页面时,我在 /locations/add/ 处收到 TemplateDoesNotExist 错误。又是这个页面在本地工作,怎么可能页面不存在呢?

这里是 urls.py sn-p:

    urlpatterns = patterns(
        '',

        url(r'^add/$', login_required(AddLocation.as_view()), name="add_location"),
)

观点:

class AddLocation(View):

    template_name = "dash/Addlocation.html"
    form = locationForm()
    def get(self, request, *args, **kwargs):
        user = User.objects.get(username=request.user.username)
        self.form.fields['existing_regions'].queryset = Region.objects.filter(location__manager=user)
        return render(request, self.template_name, {'form': self.form})

以及完整的回溯:

Traceback:
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  22.                 return view_func(request, *args, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/django/views/generic/base.py" in view
  69.             return self.dispatch(request, *args, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  87.         return handler(request, *args, **kwargs)
File "/app/pinpoint/apps/locationmanager/views.py" in get
  39.         return render(request, self.template_name, {'form': self.form})
File "/app/.heroku/python/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render
  53.     return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  162.         t = get_template(template_name)
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/loader.py" in get_template
  138.     template, origin = find_template(template_name)
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/loader.py" in find_template
  131.     raise TemplateDoesNotExist(name)

Exception Type: TemplateDoesNotExist at /locations/add/
Exception Value: dash/Addlocation.html

这是我的模板目录:

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(BASE_DIR, '../templates'),
)

这是我按要求安装的应用程序:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.formtools',
    #'rest_framework',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    #'pinpoint.apps.careers',
    #'pinpoint.apps.contact',
    'pinpoint.profile',
    'south',
    'pinpoint.apps.beaconmanager',
    'pinpoint.apps.api',
    'pinpoint.apps.geofencemanager',
    'pinpoint.apps.locationmanager',
    'pinpoint.apps.messagemanager',
    'django_extensions',



)

我的模板加载器:

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

如果需要,我可以提供更多详细信息。任何人都知道为什么这个链接在heroku上不存在但在本地存在?

【问题讨论】:

  • 同时显示您的TEMPLATE_DIRSINSTALLED_APPS 设置。
  • 我都添加了,还包括我的装载机。再次感谢。

标签: python django heroku django-templates


【解决方案1】:

好的,我已经意识到出了什么问题。

两件事:

  1. 我的应用需要的 urls.py django.core.urlresolvers import reverse
  2. template_name = "dash/Addlocation.html" 需要更改为 template_name = "dash/AddLocation.html"

感谢那些为我指明正确方向的人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 2014-07-06
    相关资源
    最近更新 更多