模板在heroku上不存在,但在本地存在

时间:2014-09-10 18:43:09

标签: python django heroku django-templates

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

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

这是urls.py片段:

    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上不存在但在本地存在?

1 个答案:

答案 0 :(得分:0)

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

两件事:

  1. 我的应用的urls.py需要django.core.urlresolvers import reverse
  2. template_name = "dash/Addlocation.html"需要更改为template_name = "dash/AddLocation.html"
  3. 感谢那些指引我正确方向的人。

相关问题