【问题标题】:Working at django templates without django forms [closed]在没有 django 表单的 django 模板上工作 [关闭]
【发布时间】:2016-05-16 23:47:02
【问题描述】:

我需要一个简单的例子,创建 django 模板而不创建 django 表单,我可以在模板中输入一些信息,我需要在视图部分保存在 mongo db 中。目前我正在使用 pymongo。

请发布一些示例

【问题讨论】:

  • 欢迎来到 Stack Overflow:您的问题太宽泛了。可能的答案太多,或者对于这种格式来说,好的答案太长了。请添加详细信息以缩小答案范围或隔离可以在几段中回答的问题。

标签: django django-templates pymongo


【解决方案1】:
Create file simple.html

<!DOCTYPE html>
<html>
    <body>
        <form id="myform" method="post" action="/">
            {% csrf_token %}
            <input type="hidden" name="var" value="15" />
            <a href="#" onclick="document.forms[0].submit();return false;">Let's go!</a>
        </form>
    </body>
</html>


And Write the view

def index(request):

    if request.method == 'POST':
        try:
            var = request.POST['var']
            # TODO use var
        except :
            print 'Where is my var?'
    return render_to_response('simple.html', {}, context_instance=RequestContext(request))



Is this one you are looking for?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2016-08-09
    • 2020-04-18
    • 1970-01-01
    • 2016-01-05
    • 2021-01-31
    相关资源
    最近更新 更多