【发布时间】:2021-05-16 09:34:28
【问题描述】:
我的 urls.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'),
]
我的views.py页面是这样的
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')
我的 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 页面。我认为我的问题出在 urls.py 或 index.html 中。
【问题讨论】:
-
/textutils/ 是否需要在 .html 文件中!
-
我不这么认为..我只是通过添加
/textutils/来测试。
标签: python html css django twitter-bootstrap