Python 我收到错误:在django中找不到页面
我的URL.py页面如下Python 我收到错误:在django中找不到页面,python,html,css,django,twitter-bootstrap,Python,Html,Css,Django,Twitter Bootstrap,我的URL.py页面如下 from django.contrib import admin from django.urls import path from . import views urlpatterns = [ path('admin/', admin.site.urls), path('',views.index,name='index'), path('analyze/',views.analyze,name='analyze'), path('about/',v
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.index,name='index'),
path('analyze/',views.analyze,name='analyze'),
path('about/',views.about,name='about'),
path('contact/',views.contact,name='contact'),
]
from django.http import HTTP Response
from django.shortcuts import render
def index(request):
return render(request,'index.html')
def analyze(request):
djtext=request.GET.get('text','default')
removepunc=request.GET.get('removepunc','off')
fullcaps=request.GET.get('fullcaps','off')
spaceremover=request.GET.get('spaceremover','off')
charcounter=request.GET.get('charcounter','off')
wordcounter=request.GET.get('wordcounter','off')
print(djtext)
#analyzed=djtext
if removepunc == 'on':
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
analyzed=""
for char in djtext:
if char not in punctuations:
analyzed=analyzed+char
params={'purpose':'Remove punctuations','analyzed_text':analyzed}
return render(request,'analyze.html',params)
elif fullcaps=='on':
# analyzed=djtext1
analyzed=""
for i in djtext:
if i==" ":
analyzed=analyzed+" "
else:
analyzed=analyzed+i.upper()
params={'purpose':'Capital Letter First','analyzed_text':analyzed}
return render(request,'analyze.html',params)
elif spaceremover == 'on':
analyzed=djtext.replace(" ","")
params={'purpose':'Space Remover','analyzed_text':analyzed}
return render(request,'analyze.html',params)
elif charcounter == 'on':
counter=0
for char in djtext:
if char==" ":
continue
else:
counter=counter+1
params={'purpose':'Character Counter','analyzed_text':counter}
return render(request,'analyze.html',params)
elif wordcounter == 'on':
counter=1
for char in djtext:
if char==' ':
counter=counter+1
params={'purpose':'Word Counter','analyzed_text':counter}
return render(request,'analyze.html',params)
else:
return HttpResponse("Error")
def about(request):
return render(request,'about.html')
def contact(request):
return render(request,'contact.html')
My views.py页面如下所示
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.index,name='index'),
path('analyze/',views.analyze,name='analyze'),
path('about/',views.about,name='about'),
path('contact/',views.contact,name='contact'),
]
from django.http import HTTP Response
from django.shortcuts import render
def index(request):
return render(request,'index.html')
def analyze(request):
djtext=request.GET.get('text','default')
removepunc=request.GET.get('removepunc','off')
fullcaps=request.GET.get('fullcaps','off')
spaceremover=request.GET.get('spaceremover','off')
charcounter=request.GET.get('charcounter','off')
wordcounter=request.GET.get('wordcounter','off')
print(djtext)
#analyzed=djtext
if removepunc == 'on':
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
analyzed=""
for char in djtext:
if char not in punctuations:
analyzed=analyzed+char
params={'purpose':'Remove punctuations','analyzed_text':analyzed}
return render(request,'analyze.html',params)
elif fullcaps=='on':
# analyzed=djtext1
analyzed=""
for i in djtext:
if i==" ":
analyzed=analyzed+" "
else:
analyzed=analyzed+i.upper()
params={'purpose':'Capital Letter First','analyzed_text':analyzed}
return render(request,'analyze.html',params)
elif spaceremover == 'on':
analyzed=djtext.replace(" ","")
params={'purpose':'Space Remover','analyzed_text':analyzed}
return render(request,'analyze.html',params)
elif charcounter == 'on':
counter=0
for char in djtext:
if char==" ":
continue
else:
counter=counter+1
params={'purpose':'Character Counter','analyzed_text':counter}
return render(request,'analyze.html',params)
elif wordcounter == 'on':
counter=1
for char in djtext:
if char==' ':
counter=counter+1
params={'purpose':'Word Counter','analyzed_text':counter}
return render(request,'analyze.html',params)
else:
return HttpResponse("Error")
def about(request):
return render(request,'about.html')
def contact(request):
return render(request,'contact.html')
从django.http导入http响应
从django.shortcuts导入渲染
def索引(请求):
返回呈现(请求'index.html')
def分析(请求):
djtext=request.GET.GET('text','default')
removepunc=request.GET.GET('removepunc','off'))
fullcaps=request.GET.GET('fullcaps','off')
spaceremover=request.GET.GET('spaceremover','off')
charcounter=request.GET.GET('charcounter','off')
wordcounter=request.GET.GET('wordcounter','off')
打印(文本)
#已分析=djtext
如果removepunc=='on':
标点符号=“”!()-[]{};:'"\,./?@#$%^&*_~'''
分析=“”
对于djtext中的字符:
如果字符不在标点符号中:
已分析=已分析+字符
params={'purpose':'Remove标点符号','analysisted_text':analysisted}
返回呈现(请求,'analyze.html',参数)
elif fullcaps=='on':
#已分析=djtext1
分析=“”
对于DJI文本:
如果i==“”:
已分析=已分析+“”
其他:
已分析=已分析+i.上()
params={'purpose':'Capital Letter First','analysisted_text':analysisted}
返回呈现(请求,'analyze.html',参数)
elif spaceremover==“开”:
已分析=djtext.replace(“,”)
params={'purpose':'Space Remover','analysisted_text':analysisted}
返回呈现(请求,'analyze.html',参数)
elif charcounter=='on':
计数器=0
对于djtext中的字符:
如果char==“”:
持续
其他:
计数器=计数器+1
参数={'purpose':'Character Counter','analysisted_text':Counter}
返回呈现(请求,'analyze.html',参数)
elif wordcounter=='on':
计数器=1
对于djtext中的字符:
如果char='':
计数器=计数器+1
params={'purpose':'Word Counter','analysisted_text':Counter}
返回呈现(请求,'analyze.html',参数)
其他:
返回HttpResponse(“错误”)
def关于(请求):
返回呈现(请求'about.html')
def联系人(请求):
返回呈现(请求'contact.html')
我的index.html页面——这里我只显示了可能出现错误的导航栏部分。我的index.html页面位于template/textutils中,关于和联系人页面也位于template/textutils中
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/textutils/about">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/textutils/contact">Contact Us</a>
</li>
</ul>
</div>
-
-
-
我正在获取index.html页面,但我无法获取about.html页面和contact.html页面。我想我的问题可能是在url.py或index.html中。您的html正在链接到
/textutils/about
<a class="nav-link" href="/textutils/about">About Us</a>
但是,您的URL似乎只需要关于
。从链接中删除textutils/
应该可以,或者将其添加到URLS.py
文件index.html中
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'about' %}">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'contact' %}">Contact Us</a>
</li>
</ul>
</div>
-
-
-
最后我得到了答案,它需要index.html中的Jinja代码,所有代码都将与以前一样。我唯一做的更改是在index.html页面中。/textutils/是否需要在.html文件中使用它!我不这么认为。.我只是通过添加
/textutils/
进行测试。谢谢您的帮助,但它也不起作用。