I have an issue with the implementation of Wiki I can't simply understand what's happening.
My code so far for urls.py:
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index"),
path("<str:title>", views.entries, name="entries"),
path("search/", views.search, name="search")
]
and for views.py:
from django.shortcuts import render
from django.http import HttpResponse
from django.urls import reverse
from django.http import HttpResponseRedirect
from markdown2 import Markdown
from django import forms
from . import util
# render wiki's index
def index(request):
return render(request, "encyclopedia/index.html", {
"entries": util.list_entries()
})
# take path, remove capitalization and query for a matching entry
def entries(request, title):
nocase_title = title.lower()
entry = util.get_entry(nocase_title)
if entry:
# convert markdown to html and render the entry route
translator = Markdown()
html = translator.convert(entry)
return render(request, "encyclopedia/entry.html", {"entry":html, "title":nocase_title.upper()})
else:
return render(request, "encyclopedia/not_found.html")
def search(request):
return render(request, "encyclopedia/search.html")
My problem is this: In the url, I can't type a pass to wiki/python or wiki/css all in lowercase. Everytime I try it, I get 404 problem returned to me. I don't have issue with the other entries, I can type wiki/django, wiki/git or wiki/html.... But the most strange part is that I can type urls including those words in all caps or half of it. For example, if I type wiki/CSS wiki/cSS, wiki/Css, or wiki/cSs AND ALL OF IT WORKS. The same goes for python. I can use wiki/pYthon, wiki/PYTHON, wiki/PyTHon, etc... I only can't access to those entries when trying to type in all-lowercase.
I am truly amazed about this issue because I can't image what causing it. As I told before, it only occur with those two entry templates (css and python), the rest work fine (I also can type all-lowercase similar words (for example, cs50 or pythagoras) and I don't get a 404 error, in those cases I receive my custome "entry not found" html template return by entries(request, title) function.
question from:
https://stackoverflow.com/questions/66051769/cs50w-project-1-wiki-django-paths-capitalization-problem-in-some-entries 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…