Using request.POST.copy() to get hidden field in html template

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using request.POST.copy() to get hidden field in html template

James McManus
I'm trying to use request.POST.copy() to get a hidden field in an html
template.  The hidden field looks like:

<input type="hidden" value="{% if post.url %}{{ post.url }}{%else
%}""{%endif%}" name="url" />

I also tried:

<input type="hidden" value="{{ post.url }}" name="url" />

In my view.py I have:

      postdata = request.POST.copy()
       url = str(postdata.get('url'))

The value of url is None.  Is there an additional trick to this?

Thanks
Jim

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Using request.POST.copy() to get hidden field in html template

DrBloodmoney
On Wed, Nov 30, 2011 at 7:43 PM, jim <[hidden email]> wrote:

> I'm trying to use request.POST.copy() to get a hidden field in an html
> template.  The hidden field looks like:
>
> <input type="hidden" value="{% if post.url %}{{ post.url }}{%else
> %}""{%endif%}" name="url" />
>
> I also tried:
>
> <input type="hidden" value="{{ post.url }}" name="url" />
>
> In my view.py I have:
>
>      postdata = request.POST.copy()
>       url = str(postdata.get('url'))
>
> The value of url is None.  Is there an additional trick to this?

1. Make sure that the hidden field is inside of the <form></form> tags.

2. You shouldn't need to copy the QueryDict to get the value:

url = request.POST.get('url', 'default') # or request.POST['url']

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.