Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Else语句不起作用。获取错误:TypeError:markdown()缺少1个必需的位置参数:';文本';_Python_Django_Cs50 - Fatal编程技术网

Python Else语句不起作用。获取错误:TypeError:markdown()缺少1个必需的位置参数:';文本';

Python Else语句不起作用。获取错误:TypeError:markdown()缺少1个必需的位置参数:';文本';,python,django,cs50,Python,Django,Cs50,Django代码用于创建一个条目页面,其中访问/wiki/title,其中title是百科全书条目的标题,应该呈现一个显示该百科全书条目内容的页面。视图应该通过调用适当的util函数来获取百科全书条目的内容。如果请求的条目不存在,则应向用户显示一个错误页面,表明未找到其请求的页面 但若语句工作正常,那个么else语句就不工作了。当我浏览时,它应该引导我到那个专用页面。但我得到一个错误:markdown()缺少1个必需的位置参数:“text”。请告知如何减轻此错误 视图.py from markd

Django代码用于创建一个条目页面,其中访问/wiki/title,其中title是百科全书条目的标题,应该呈现一个显示该百科全书条目内容的页面。视图应该通过调用适当的util函数来获取百科全书条目的内容。如果请求的条目不存在,则应向用户显示一个错误页面,表明未找到其请求的页面

但若语句工作正常,那个么else语句就不工作了。当我浏览时,它应该引导我到那个专用页面。但我得到一个错误:markdown()缺少1个必需的位置参数:“text”。请告知如何减轻此错误

视图.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                                         
    })
from django.urls import path
from . import views

urlpatterns = [
    path("", views.index, name="index"),
    path("wiki/<str:entry>", views.entry, name="entry")
]
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
url.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                                         
    })
from django.urls import path
from . import views

urlpatterns = [
    path("", views.index, name="index"),
    path("wiki/<str:entry>", views.entry, name="entry")
]
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

正如Kaleba所说,尝试将views.py中的行更改为


“entry”:标记(entryPage)

函数缺少参数。给它一个论点。这意味着括号中缺少了一些内容
markdown(“一些文本必须放在这里,假设它是字符串”)
这真的很令人伤心,因为错误信息从字面上告诉你什么是错误的,在大多数情况下,如果你只搜索错误,你会得到答案。我对Django一无所知,但我很高兴你能指出具体的问题谢谢你@julianofischer和Kaleba KB Keitshokile的帮助。后来我终于发现了代码的错误。:)服务器是从上一个实例运行的,因此没有对我的代码进行任何更改。建议像我这样的初学者在修改代码后重新启动服务器。