Django 1.8渲染错误TemplateDoesNotExist at

时间:2015-10-13 18:40:19

标签: jquery python html ajax django

我正在研究Django 1.8

我的终端控制台 - [13 / Oct / 2015 23:37:37]" GET / blogu / search_top /?query_string = H HTTP / 1.1" 500 13646

我的浏览器 我的views.py -

def search_top(request):
    str=request.GET["query_string"]
    #print str
    result=get_category_list(100,str)
    cat_list=[]
    for name in result:
        cat=Category.objects.get(name=name)
        cat_list.append(cat)
    #return HttpResponse("Results") # getting printed
    return render(request,"blogu/search_results.html", {'cats':cat_list} )

search_results.html -

<u1 class ="search-results">
{% if cats %}
    {% for cat in cats %}
        <li><a href="{% url 'category' cat.slug %}">{{ cat.name }}</a></li>
    {% endfor %}
{% endif %}
</u1>

settings.py -

import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

jquery文件 -

$('#suggestion_search').keyup(function(){
//alert('Hello');
var search_term;
search_term=$(this).val();
 $.ajax({
type:"GET",
url: "/blogu/search_top/",
data: {query_string: search_term},
success: function(newData){
    $('#search_results').html(newData);
}
 });
  });

浏览器的回复 -

TemplateDoesNotExist at /blogu/search_top/blogu/search_results.html

Request Method: GET
Request URL: http://localhost:8000/blogu/search_top/?query_string=H
Template loader Error:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
C:\Python27\Projects\Django\pd\templates\blogu\search_results.html (File        does not exist)
Using loader django.template.loaders.app_directories.Loader:
 C:\Python27\Lib\sitepackages\django\contrib\admin\templates\blogu\search_results.html (File does not exist)
C:\Python27\Lib\site-packages\django\contrib\auth\templates\blogu\search_results.html (File does not exist)
C:\Python27\Lib\site-packages\registration\templates\blogu\search_results.html (File does not exist)
C:\Python27\Lib\site-packages\bootstrap_toolkit\templates\blogu\search_results.html (File does not exist)
Traceback:
File "C:\Python27\Lib\site-packages\django\core\handlers\base.py" in get_response
 132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\Projects\Django\pd\blogu\views.py" in search_top
   387.     return render(request,"blogu/search_results.html", {'cats':cat_list} )
 File "C:\Python27\Lib\site-packages\django\shortcuts.py" in render
   67.             template_name, context, request=request, using=using)
 File "C:\Python27\Lib\site-packages\django\template\loader.py" in render_to_string
   98.             template = get_template(template_name, using=using)
 File "C:\Python27\Lib\site-packages\django\template\loader.py" in get_template
   46.     raise TemplateDoesNotExist(template_name)

Exception Type: TemplateDoesNotExist at /blogu/search_top/
Exception Value: blogu/search_results.html
Request information:
GET:
query_string = u'H'

我非常确定search_results.html位于blogu / templates中 如果我返回一个httpresponse而不是html,它就会被打印出来。 Thanku

0 个答案:

没有答案