簡體   English   中英

在Django中傳遞參數以形成動作?

[英]Passing parameters to form action in Django?

模板:

<form method="post" action="/reply/{{feed.id}}/">

    {{rform.as_p}}

    <input type="submit" value="send" /> 

</form>

和網址:

(r'^reply/(\d+)/$',reply),

但是,當我們提交表單時, {{feed.id}}不會被翻譯,並且網址會直接指向/reply//

表單操作中是否不允許使用參數?
如果允許,那么為什么在這里不起作用?

謝謝

如果{{ feed.id }}為空,則意味着feed.id為空,或者feed為None。 使用render_to_response渲染模板時,請確保在視圖上下文中傳遞feed

我認為您的供稿是字典對象?

在您的views.py模塊中

from django.shortcuts import render_to_response;

def myforms(request):
    feed = {"id":"369"}
    return render_to_response('html-template/blank.html', {'feed': feed})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM