Advertisement
oquidave

django template problem

Nov 17th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.88 KB | None | 0 0
  1. #pilot.views.py file
  2.  
  3. def current_datetime(request):
  4.     now = datetime.now();
  5.     #html = "<html><body>The time is:  %s.</body></html>" % now
  6.     t = get_template("current_datetime.html")
  7.     c = Context({"date": now})
  8.     html = t.render(c)
  9.     return HttpResponse(html)
  10.  
  11. #current_datetime.html under templates directory in the project
  12.  
  13. <html>
  14. <head>
  15. <title>Current date and time</title>
  16. </head>
  17. <body>
  18. The current time is {{date}}
  19. </body>
  20. </html>
  21.  
  22. #settings.py
  23.  
  24. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  25. import os
  26. BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  27.  
  28.  
  29.  
  30. # Quick-start development settings - unsuitable for production
  31. # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
  32.  
  33. # SECURITY WARNING: keep the secret key used in production secret!
  34. SECRET_KEY = '=glaw6%x(w4y$@mqy7x&b03n+brhm!@s3$dtzk7j(-n(d#++1@'
  35.  
  36. # SECURITY WARNING: don't run with debug turned on in production!
  37. DEBUG = True
  38.  
  39. TEMPLATE_DEBUG = True
  40.  
  41. PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
  42. TEMPLATES_DIR = [os.path.join(BASE_DIR, 'templates')]
  43.  
  44.  
  45.  
  46.  
  47. #traceback
  48. Environment:
  49.  
  50.  
  51. Request Method: GET
  52. Request URL: http://127.0.0.1:8000/date/
  53.  
  54. Django Version: 1.6
  55. Python Version: 2.7.3
  56. Installed Applications:
  57. ('django.contrib.admin',
  58.  'django.contrib.auth',
  59.  'django.contrib.contenttypes',
  60.  'django.contrib.sessions',
  61.  'django.contrib.messages',
  62.  'django.contrib.staticfiles')
  63. Installed Middleware:
  64. ('django.contrib.sessions.middleware.SessionMiddleware',
  65.  'django.middleware.common.CommonMiddleware',
  66.  'django.middleware.csrf.CsrfViewMiddleware',
  67.  'django.contrib.auth.middleware.AuthenticationMiddleware',
  68.  'django.contrib.messages.middleware.MessageMiddleware',
  69.  'django.middleware.clickjacking.XFrameOptionsMiddleware')
  70.  
  71. Template Loader Error:
  72. Django tried loading these templates, in this order:
  73. Using loader django.template.loaders.filesystem.Loader:
  74. Using loader django.template.loaders.app_directories.Loader:
  75. /usr/lib/python2.7/site-packages/django/contrib/admin/templates/current_datetime.html (File does not exist)
  76. /usr/lib/python2.7/site-packages/django/contrib/auth/templates/current_datetime.html (File does not exist)
  77.  
  78.  
  79.  
  80. Traceback:
  81. File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  82.   114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  83. File "/home/oquidave/workspace/python/pilot/pilot/views.py" in current_datetime
  84.   10.     t = get_template("current_datetime.html")
  85. File "/usr/lib/python2.7/site-packages/django/template/loader.py" in get_template
  86.   138.     template, origin = find_template(template_name)
  87. File "/usr/lib/python2.7/site-packages/django/template/loader.py" in find_template
  88.   131.     raise TemplateDoesNotExist(name)
  89.  
  90. Exception Type: TemplateDoesNotExist at /date/
  91. Exception Value: current_datetime.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement