Django code is to create an Entry Page where Visiting /wiki/title, where TITLE is the title of an encyclopedia entry, should render a page that displays the contents of that encyclopedia entry. The view should get the content of the encyclopedia entry by calling the appropriate util function. If an entry is requested that does not exist, the user should be presented with an error page indicating that their requested page was not found.
But if statement is working fine, but else statement is not working. When I am browsing http://127.0.0.1:8000/wiki/CSS, it should navigate me to that dedicated page. But I am getting an error: markdown() missing 1 required positional argument: 'text'. Please advise how to mitigate this error?
views.py
from markdown import markdown from django.shortcuts import render from . import util #EntryPage using title def entry(request, entry): #markdowner = markdown() entryPage = util.get_entry(entry) #Displays the requested entry page, if it exists if entryPage is None: return render(request, "encyclopedia/nonExistingEntry.html", { "entryTitle": entry }) # Title exists, convert md to HTML and return rendered template else: return render(request, "encyclopedia/entry.html", { "entry": markdown().convert(entryPage), "entryTitle": entry }) urls.py
from django.urls import path from . import views urlpatterns = [ path("", views.index, name="index"), path("wiki/<str:entry>", views.entry, name="entry") ] util.py
def get_entry(title): """ Retrieves an encyclopedia entry by its title. If no such entry exists, the function returns None. """ try: f = default_storage.open(f"entries/{title}.md") return f.read().decode("utf-8") except FileNotFoundError: return None https://stackoverflow.com/questions/66926759/else-statement-is-not-working-getting-error-typeerror-markdown-missing-1-re April 03, 2021 at 08:42AM
没有评论:
发表评论