Sunday, April 20, 2014

Re: POST URL questions

Hi,

POST variables are appended to the HTTP request body instead of the URL [0].

If you want a variable to be available in the request.POST dictionary,
the browser must send it as a POST variable (in the request body). You
could use a hidden input to do it:

<form method="post" ...>
<input type="hidden" name="userid" value="{{ request.user_id }}">
</form>

[0] https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Sending_and_retrieving_form_data#The_method_attribute

On Sat, Apr 19, 2014 at 5:12 AM, nobody <jupiter.hce@gmail.com> wrote:
> Hi,
>
> I set up an URL when cliking a submit button, I got
> http://myhost.com/user/?userid=5987.
>
> In REQEST, I can get useid = request.GET['userid'], but in POST, I could not
> get the variable from the POST:
>
> if userid in request.POST
> userid = request.POST.get("userid", "")
>
> Despite the userid=5987 was included in the URL, the above check failed, how
> can I get variables in URL from POST? Also, not sure if the userid =
> request.POST.get("userid", "")
> is the correct syntax to get variables from request.POST?
>
> 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 current URL I can put it in the action, for example, like action
> = "{{ current_url }}/?userid={{ request.user_id }}"?
>
> Thank you.
>
> Kind regards.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6438db49-a616-48b0-ae16-dfaa51a2f70f%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABoKswjjgKH53W2f_xtycqKM1%2BUSJufWFsm_dM%2BvbGDuJXo6gg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment