I am new to Django and just follow the Django white paper, but here is the problem.
I am creating a new Django project with
Django 1.8.2 + PyCharm 4.5.1 + Python 3.4.3 + Windows 8.1
- mysite - main - migrations __init__.py __init__.py admin.py models.py tests.py views.py - mysite __init__.py settings.py urls.py wsgi.py - templates hello.html db.sqlite3 manage.py
most of them are created automatically, which I changed as follows:
Templates / hello.html
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>Django test</title> </head> <body> hello world! </body> </html>
MySite / urls.py
from django.conf.urls import include, url from django.contrib import admin from main.views import hello urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^hello/$', hello), ]
Primary / views.py
from django.shortcuts import render_to_response def hello(request): return render_to_response('hello.html', locals())
and run the run and go to localhost: 8080, here are the results:
TemplateDoesNotExist at /hello/ hello.html Request Method: GET Request URL: http://127.0.0.1:8000/hello/ Django Version: 1.8.2 Exception Type: TemplateDoesNotExist Exception Value: hello.html Exception Location: C:\Python34\lib\site-packages\django\template\loader.py in get_template, line 46 Python Executable: C:\Python34\python.exe Python Version: 3.4.3 Python Path: ['C:\\Users\\kant\\Desktop\\code\\PycharmProjects\\mysite', 'C:\\Users\\kant\\Desktop\\code\\PycharmProjects\\mysite', 'C:\\Windows\\SYSTEM32\\python34.zip', 'C:\\Python34\\DLLs', 'C:\\Python34\\lib', 'C:\\Python34', 'C:\\Python34\\lib\\site-packages']
if i change view.py as
from django.http import HttpResponse def hello(request): return HttpResponse("hello world")
It works correctly.
I think this may be caused by the path pattern, here is setup.py generated automatically without changes:
""" Django settings for mysite project. Generated by 'django-admin startproject' using Django 1.8.2. For more information on this file, see https://docs.djangoproject.com/en/1.8/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.8/ref/settings/ """