Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.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 /edit:edit()处的TypeError缺少1个必需的位置参数:';条目';_Python_Html_Django - Fatal编程技术网

Python /edit:edit()处的TypeError缺少1个必需的位置参数:';条目';

Python /edit:edit()处的TypeError缺少1个必需的位置参数:';条目';,python,html,django,Python,Html,Django,我是Django的新手,我正在做一个web应用程序项目。此特定页面应编辑条目并保存条目。但我一直得到缺少的1个必要参数 Views.py url.py 从django.url导入路径 从。导入视图 urlpatterns = [ path("", views.index, name="index"), path("wiki/<str:entry>", views.entry, name="entry

我是Django的新手,我正在做一个web应用程序项目。此特定页面应编辑条目并保存条目。但我一直得到缺少的1个必要参数

Views.py

url.py

从django.url导入路径

从。导入视图

urlpatterns = [
    path("", views.index, name="index"),
    path("wiki/<str:entry>", views.entry, name="entry"),
    path("search", views.search, name="search"),
    path("newEntry", views.newEntry, name="newEntry"),
    path("edit", views.edit, name="edit"),

urlpatterns=[
路径(“,views.index,name=“index”),
路径(“wiki/”,views.entry,name=“entry”),
路径(“搜索”,views.search,name=“搜索”),
路径(“newEntry”,views.newEntry,name=“newEntry”),
路径(“编辑”,views.edit,name=“编辑”),
编辑HTML

{%extends“encyclopedia/layout.html”%}
{%block title%}
编辑{{name}
{%endblock%}
{%block body%}
{{title}}
{%csrf_令牌%}
{{edit}}

单击“保存”按钮将条目保存到百科全书


{%endblock%}
条目HTML

{%extends“encyclopedia/layout.html”%}
{%block title%}
百科全书
{%endblock%}
{%block body%}
{{title}}
{{entry | safe}}


{%endblock%}
当我更改此特定url时:

path("edit/<str:entry>", views.edit, name="edit"),
path(“edit/”,views.edit,name=“edit”),
我得到一个不同的问题:
为未找到任何参数的“edit”反转。尝试了1种模式:[“edit/(?P[^/]+)$”]

此行中的

URL.py
文件存在问题:

路径(“编辑”,views.edit,name=“编辑”), 因为
views.edit
要求您必须在
url
中提供两个参数
request
entry
。在您的情况下,entry丢失。请尝试在urlspatterns路径中添加条目,在这种情况下,我希望您的条目是
int

path(“edit/”,views.edit,name=“edit”),
此条目可以是您的模型pk或任何您想要的内容。在修改
urlspatterns
后,无论何时在html中调用编辑视图,您都需要执行以下操作:

{%url'edit'条目=您的条目\值%}
而不是:

{%url'编辑“%”

这是否回答了您的问题?由于编辑视图需要名为
entry
的强制参数,您应该更新
url
标记用法。要获得更清楚的答案,请共享您的
utils.get\u entry()
function.jade util.get\u entry()接受字符串:
def get_entry(title):“按标题检索百科全书条目。如果不存在此类条目,则函数将返回无。”
try:f=default_storage.open(f“entries/{title}.md”)返回f.read().decode(“utf-8”)除FileNotFoundError外:return None`util.get_entry()接受字符串:
def get_entry(title):“”“按标题检索百科全书条目。如果不存在此类条目,则函数将不返回任何内容。”“”try:f=default_storage.open(f“entries/{title}.md”)返回f.read().decode(“utf-8”),FileNotFoundError除外:返回None
{% extends "encyclopedia/layout.html" %}


{% block title %}
    Edit {{name}}
{% endblock %}


{% block body %}
  <h1>{{title}}</h1>
  <form action= "{% url 'edit' %}" method="POST">
    {% csrf_token %}
    {{ edit }}
  <br>
  <input class="save btn btn-info" type="submit" value="save"/>
  </form>
  <p> Click the "save" button to save your entry to the encyclopedia.</p>
  <br>



<a href = "{% url 'index' %}"> Return Home</a>
{% endblock %}
{% extends "encyclopedia/layout.html" %}




{% block title %}
    Encyclopedia
{% endblock %}

{% block body %}

    <h1>{{title}}</h1>


    {{entry | safe}}

<a href = "{% url 'edit' %}"> Edit Content</a>
<br>
<br>
<a href = "{% url 'index' %}"> Return Home</a>
{% endblock %}
path("edit/<str:entry>", views.edit, name="edit"),