问题描述:

I have a html file ('search.html') with a form on it. I have saved it to ~/Django/Templates just for the sake of argument. The Django book said it doesn't matter where I save it, because the framework will find it. Anyway, I have set up a function in the views.py file to render this file. Here it is:

from django.http import HttpResponse

from django.shortcuts import render_to_response

def search(request):

return render_to_response('search.html')

I have this function called in the urls.py file as well:

urlpatterns = patterns('',

(r'^$', index),

(r'^search/$', search),

However, whenever I go to visit the page with the ~/search in the URL, I get the following:

TemplateDoesNotExist at /search/

What's the problem?

网友答案:

In your settings.py file there is a line...

TEMPLATE_DIRS = (...)

You want to make sure the directory containing the template is in that tuple.

相关阅读:
Top