Re: URL variables failed to be found from POST

19 views
Skip to first unread message

Russell Keith-Magee

unread,
Apr 20, 2014, 8:39:32 PM4/20/14
to Django Users

On Sat, Apr 19, 2014 at 6:36 PM, nobody <jupit...@gmail.com> wrote:
Hi,

I set up an URL when cliking a submit button, I got http://myhost.com/user/?userid=5987.

If it is a REQEST, I can get useid = request.GET['userid']. But in POST, I could not get the variable from the POST, I could not even find the variable in POST, the following check userid in request.POST was false, and I cannot check if the syntax of next statement "userid = request.POST.get("userid", "")" is correct or not.

if userid in request.POST
    userid = request.POST.get("userid", "")

 

Also, at the moment, I made a hard coded absolutely URL in the submit action:

<form method="post" action="http://myhost.com/user/?userid={{ request.user_id }}">{% csrf_token %}

Is there a key word for current URL I can put it in the action, for example, like action = "{{ current_url }}/?userid={{ request.user_id }}"?

Hi,

request.GET contains the URL keywords, regardless of whether it's a GET or POST request. In the case of a GET request, *all* the form data is contained in request.GET if it's a GET request; if it's a POST request, request.POST contains the form data, and request.GET contains the URL arguments.

I hope that helps!
 
Yours,
Russ Magee %-)
Reply all
Reply to author
Forward
0 new messages