gpt4 book ai didi

python - 我在 Django 中的 urls.py 中的 url 模式不匹配

转载 作者:太空宇宙 更新时间:2023-11-04 05:31:57 24 4
gpt4 key购买 nike

这是我的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 - 我在 Django 中的 urls.py 中的 url 模式不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11326748/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com