我在Django中的urls.py中的网址格式不匹配 - python

这是我的views.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))

这是我的results.html(存储在/home/pooja/Desktop/my_templates/search/results.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>

当我在服务器上运行此应用程序时,search.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.

为什么会这样呢?我将所有skey.py,xml文档和xml.txt存储在搜索应用程序中。

参考方案

表单上的操作是/front_page/。如果希望它转到当前URL,则应完全省略action属性。

Python 3运算符>>打印到文件 - python

我有以下Python代码编写项目的依赖文件。它可以在Python 2.x上正常工作,但是在使用Python 3进行测试时会报告错误。depend = None if not nmake: depend = open(".depend", "a") dependmak = open(".depend.mak&#…

Python ElementTree:在循环中替换元素 - python

我正在尝试创建一个脚本,该脚本循环创建一个xml文件,并为两个元素增加值。 (使用netaddr的IP地址,以及递增的tag / member元素,tag01-tag10)from netaddr import IPNetwork import xml.dom.minidom import lxml.etree as etree import xml.etr…

Python Pandas导出数据 - python

我正在使用python pandas处理一些数据。我已使用以下代码将数据导出到excel文件。writer = pd.ExcelWriter('Data.xlsx'); wrong_data.to_excel(writer,"Names which are wrong", index = False); writer.…

如何使用BeautifulSoup在<tr>中捕获特定的<td> - python

尝试从nyc Wiki页面中的高中列表中获取所有高中名称。我已经写了足够多的脚本,可以让我获取包含在高中,学业和入学条件列表的表的<tr>标记中的所有信息-但是我如何才能缩小到我认为的范围内在td[0]内休息(会弹出KeyError)-只是学校的名称?到目前为止我写的代码:from bs4 import BeautifulSoup from ur…

将python scikit学习模型导出到pmml - python

我想将python scikit-learn模型导出到PMML。哪个python软件包最合适?我阅读了有关Augustus的内容,但是我无法使用scikit-learn模型找到任何示例。 python大神给出的解决方案 SkLearn2PMML是 JPMML-SkLearn命令行应用程序周围的薄包装。有关受支持的Scikit-Learn Estimator和…