第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

django 無(wú)反向匹配在 / 類型錯(cuò)誤 - 缺少所需的位置參數(shù)

django 無(wú)反向匹配在 / 類型錯(cuò)誤 - 缺少所需的位置參數(shù)

蝴蝶刀刀 2022-09-27 16:16:17
path('administration/delete-post/', administration_views.delete_upload, name='delete_upload'),path('administration/delete-post/<slug:post_slug>', administration_views.delete_upload, name='delete_upload'),出于某種原因,當(dāng)我添加刪除類時(shí),我不得不添加兩個(gè)url模式。當(dāng)我注釋掉第一條路徑時(shí),它給了我一個(gè)錯(cuò)誤Reverse for 'NoReverseMatch at /administration/delete_upload' with no arguments not found. 1 pattern(s) tried: ['administration/delete\\-post/(?P<post_slug>[-a-zA-Z0-9_]+)$']我甚至在html上陳述了鼻涕蟲。{% for post in posts %}    <a href="{% url 'delete_upload' %}{{ post.slug }}">Delete Upload</a>{% endif %}使用兩個(gè)相同的URL模式,它以某種方式工作正常,但現(xiàn)在我想添加一個(gè)確認(rèn)頁(yè)面,它再次導(dǎo)致錯(cuò)誤。views.pydef delete_upload(request, post_slug):   post = get_object_or_404(VideoPost, slug=post_slug)   if request.method == "POST":       post.delete()   context = {       "post": post   }   return render(request, "administration/confirm_delete.html", context)confirm_delete.html{% block content %}<form action="." method="POST">{% csrf_token %}    <h1>Are you sure you want to delete</h1>    <p>{{post.title}}</p>    <a href="../">Cancel</a><input type="submit" value="Confirm"></form>{% endblock %}錯(cuò)誤TypeError at /administration/delete-post/delete_upload() missing 1 required positional argument: 'post_slug'它引導(dǎo)我使用url上的slug正確confirm_delete頁(yè)面,但是當(dāng)我單擊確認(rèn)時(shí),slug在URL上消失了,并且它導(dǎo)致了似乎的錯(cuò)誤。我看到了問(wèn)題,但我無(wú)法解決它...請(qǐng)幫忙。感謝您的任何幫助
查看完整描述

2 回答

?
慕桂英546537

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊

在文件中移除path('administration/delete-post/',urls.py


在 HTML 中,將你與網(wǎng)址命名空間一起傳遞templatepost.slug


{% for post in posts %}

    <a href="{% url 'delete_upload' post.slug %}">Delete Upload</a>

{% endif %}


查看完整回答
反對(duì) 回復(fù) 2022-09-27
?
胡說(shuō)叔叔

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊

您不正確地使用了 url 模板標(biāo)記。在網(wǎng)頁(yè)中,你需要替換

<a href="{% url 'delete_upload' %}{{ post.slug }}">Delete Upload</a>

<a href="{% url 'delete_upload' slug=post.slug %}">Delete Upload</a>



查看完整回答
反對(duì) 回復(fù) 2022-09-27
  • 2 回答
  • 0 關(guān)注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)