Advertisement
oquidave

django template problem

Nov 17th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. """
  25. Django settings for pilot project.
  26.  
  27. For more information on this file, see
  28. https://docs.djangoproject.com/en/1.6/topics/settings/
  29.  
  30. For the full list of settings and their values, see
  31. https://docs.djangoproject.com/en/1.6/ref/settings/
  32. """
  33.  
  34. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  35. import os
  36. BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  37.  
  38.  
  39.  
  40. # Quick-start development settings - unsuitable for production
  41. # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
  42.  
  43. # SECURITY WARNING: keep the secret key used in production secret!
  44. SECRET_KEY = '=glaw6%x(w4y$@mqy7x&b03n+brhm!@s3$dtzk7j(-n(d#++1@'
  45.  
  46. # SECURITY WARNING: don't run with debug turned on in production!
  47. DEBUG = True
  48.  
  49. TEMPLATE_DEBUG = True
  50.  
  51. PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
  52. TEMPLATES_DIR = [os.path.join(BASE_DIR, 'templates')]
  53.  
  54. ALLOWED_HOSTS = []
  55.  
  56.  
  57. # Application definition
  58.  
  59. INSTALLED_APPS = (
  60.                   'pilot',
  61.     'django.contrib.admin',
  62.     'django.contrib.auth',
  63.     'django.contrib.contenttypes',
  64.     'django.contrib.sessions',
  65.     'django.contrib.messages',
  66.     'django.contrib.staticfiles',
  67. )
  68.  
  69. MIDDLEWARE_CLASSES = (
  70.     'django.contrib.sessions.middleware.SessionMiddleware',
  71.     'django.middleware.common.CommonMiddleware',
  72.     'django.middleware.csrf.CsrfViewMiddleware',
  73.     'django.contrib.auth.middleware.AuthenticationMiddleware',
  74.     'django.contrib.messages.middleware.MessageMiddleware',
  75.     'django.middleware.clickjacking.XFrameOptionsMiddleware',
  76. )
  77.  
  78. ROOT_URLCONF = 'pilot.urls'
  79.  
  80. WSGI_APPLICATION = 'pilot.wsgi.application'
  81.  
  82.  
  83. # Database
  84. # https://docs.djangoproject.com/en/1.6/ref/settings/#databases
  85.  
  86. DATABASES = {
  87.     'default': {
  88.         'ENGINE': 'django.db.backends.sqlite3',
  89.         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  90.     }
  91. }
  92.  
  93. # Internationalization
  94. # https://docs.djangoproject.com/en/1.6/topics/i18n/
  95.  
  96. LANGUAGE_CODE = 'en-us'
  97.  
  98. TIME_ZONE = 'UTC'
  99.  
  100. USE_I18N = True
  101.  
  102. USE_L10N = True
  103.  
  104. USE_TZ = True
  105.  
  106.  
  107. # Static files (CSS, JavaScript, Images)
  108. # https://docs.djangoproject.com/en/1.6/howto/static-files/
  109.  
  110. STATIC_URL = '/static/'
  111.  
  112.  
  113.  
  114.  
  115.  
  116. #traceback
  117. Environment:
  118.  
  119.  
  120. Request Method: GET
  121. Request URL: http://127.0.0.1:8000/date/
  122.  
  123. Django Version: 1.6
  124. Python Version: 2.7.3
  125. Installed Applications:
  126. ('django.contrib.admin',
  127.  'django.contrib.auth',
  128.  'django.contrib.contenttypes',
  129.  'django.contrib.sessions',
  130.  'django.contrib.messages',
  131.  'django.contrib.staticfiles')
  132. Installed Middleware:
  133. ('django.contrib.sessions.middleware.SessionMiddleware',
  134.  'django.middleware.common.CommonMiddleware',
  135.  'django.middleware.csrf.CsrfViewMiddleware',
  136.  'django.contrib.auth.middleware.AuthenticationMiddleware',
  137.  'django.contrib.messages.middleware.MessageMiddleware',
  138.  'django.middleware.clickjacking.XFrameOptionsMiddleware')
  139.  
  140. Template Loader Error:
  141. Django tried loading these templates, in this order:
  142. Using loader django.template.loaders.filesystem.Loader:
  143. Using loader django.template.loaders.app_directories.Loader:
  144. /usr/lib/python2.7/site-packages/django/contrib/admin/templates/current_datetime.html (File does not exist)
  145. /usr/lib/python2.7/site-packages/django/contrib/auth/templates/current_datetime.html (File does not exist)
  146.  
  147.  
  148.  
  149. Traceback:
  150. File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  151.   114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  152. File "/home/oquidave/workspace/python/pilot/pilot/views.py" in current_datetime
  153.   10.     t = get_template("current_datetime.html")
  154. File "/usr/lib/python2.7/site-packages/django/template/loader.py" in get_template
  155.   138.     template, origin = find_template(template_name)
  156. File "/usr/lib/python2.7/site-packages/django/template/loader.py" in find_template
  157.   131.     raise TemplateDoesNotExist(name)
  158.  
  159. Exception Type: TemplateDoesNotExist at /date/
  160. Exception Value: current_datetime.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement