如何在没有形式的POST请求中发送url参数 [英] how to send url parameter in POST request without form

查看:155
本文介绍了如何在没有形式的POST请求中发送url参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在url中传递参数.我无法像往常一样在GET请求中发送它,变量和值显示在请求的地址栏中.因此,最终用户可以更改此变量值的值并发送将被处理的请求.

I have to pass a parameter in url. I can't send it in as usual GET request the variable and value is shown in the address bar with the request. So, the end user can change the value for this variable value and send request which will be processed.

href="url=/admin/usermanagement/?flag=2

我要发送隐藏的flag=2

现在这作为GET请求进行,并且在地址栏中可以看到它.如果您有任何想法将其更改为POST以隐藏并发送值,请提出您的建议.

now this goes as a GET request and it is seen in the address bar. Please give your suggestion if you have any idea on changing this to POST to hide and send the value.

推荐答案

您仍然可以使用html表单,但可以从用户隐藏"它:

You can still use a html form but "hide" it from the user:

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

视图:

def index(request):
    if request.method == 'POST':
        try:
            flag = request.POST['flag']
            # TODO use flag
        except KeyError:
            print 'Where is my flag?'

    return render_to_response('index.html', {},
        context_instance=RequestContext(request))

这篇关于如何在没有形式的POST请求中发送url参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆