我的url模式网址.py在Django不匹配

2024-04-19 20:14:40 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的视图.py文件

#!/usr/bin/python 

from django.template import Context, loader, RequestContext
from django.http import HttpResponse
from skey import find_root_tags, count, sorting_list
from search.models import Keywords
#from django.shortcuts import render_to_response as rr

def front_page(request):

    if request.method == 'POST' :
        str1 = request.POST['word'] 
        fo = open("xml.txt","r")
        for i in range(count.__len__()):

             file = fo.readline()
             file = file.rstrip('\n')
             find_root_tags(file,str1,i)    

             list.append((file,count[i]))

             sorting_list(list)

        for name, count in list:
            s = Keywords(file_name=name,frequency_count=count)
            s.save()

        fo.close()
        return HttpResponseRedirect('/results/')

    else :  
        str1 = ''
        list = []
        template = loader.get_template('search/search.html')
        c = RequestContext(request)
        response = template.render(c)
        return HttpResponse(response)

def results(request):

    list1 = Keywords.objects.all()
    t = loader.get_template('search/results.html')
    c = Context({'list1':list1,
    })

    return HttpResponse(t.render(c))

这是我的结果.html(存储在/home/pooja/Desktop/my\u templates/search中)/结果.html, (这里是我的应用程序名):

<html>
<body bgcolor = "#9ACD32">
<style type="text/css">
    h1 {
         position: absolute;
         top:   200px;
         left:  480px;
       }    

form #Edit1 { position: relative; 
              top: 245px; 
              left:   480px; 
            }

form #Edit2 { position: relative; 
              top:    220px; 
              left:   680px; 
            }
</style>
<font size="5" face="arial" color="#0000FF">
<h1>Search Page</h1>
</font>
<hr/>
<br/>
<br/>
<Form Method ="POST">
<div id="Edit1">
<INPUT TYPE = 'text'  name ='word' VALUE ="">
</div>
<div id="Edit2">
<INPUT TYPE = "Submit" VALUE = "Search">
</div>
</FORM>
</body>
</html>

当我在服务器上运行这个应用程序时搜索.html页面出现了,当我输入一个单词“book”时,它给了我一个错误:

Using the URLconf defined in mysite.urls, Django tried these URL patterns,in this order:
^search/$
^admin/
The current URL, front_page/, didn't match any of these.

为什么会这样?我有我所有的斯凯比、xml文档和xml.txt文件存储在搜索应用程序中。你知道吗


Tags: djangonameinfromimportdivsearchrequest