Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.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
使用django模板而不使用django表单_Django_Django Templates_Pymongo - Fatal编程技术网

使用django模板而不使用django表单

使用django模板而不使用django表单,django,django-templates,pymongo,Django,Django Templates,Pymongo,我需要一个简单的例子,创建django模板而不创建django表单,我可以在模板中输入一些信息,我需要在视图部分保存在mongo db中。目前我正在使用pymongo 请发布一些示例创建文件simple.html Create file simple.html <!DOCTYPE html> <html> <body> <form id="myform" method="post" action="/">

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

请发布一些示例

创建文件simple.html
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?
{%csrf_令牌%} 然后写下视图 def索引(请求): 如果request.method==“POST”: 尝试: var=request.POST['var'] #TODO使用变量 除: 打印“我的var在哪里?” 返回render_to_响应('simple.html',{},context_实例=RequestContext(request)) 这是你要找的吗?
欢迎来到堆栈溢出:您的问题太广泛了。可能的答案太多,或者好的答案对于这种格式来说太长。请添加详细信息,以缩小答案集或隔离可以在几段中回答的问题。