开发者

Django Template does not exist in production server but is working in :8000

Hi guys im having a problem with my own django server (at home), django can't find templates, my error code django is looking in the correct place (/var/www/project/templates) but nothing happen

Template does not exist but all path are fine.

but using test server :8000 all is fine, i dont know how ill fix this

edit

this is perfect for get the template:

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

Template path

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(reques开发者_如何学Ct, *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

Any idea?

thanks


Trivial, but I have seen instances where people forget to add the concerned application in the installed apps and get the template not found error.


there might be an error in the template. Have you got TEMPLATE_DEBUG = True in the settings? And you've set TEMPLATE_DIRS as well?

Try loading the template via the python shell on your server:

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' })

It might throw an error and give you a further clue.


Add this to your settings file:

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"),
)

Working perfectly fine for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜