How does django pass data through post?

241 views
Skip to first unread message

Jordan W

unread,
Nov 28, 2016, 7:34:19 PM11/28/16
to Django users
Hi,

I have been working on a small project for myself and some friends, and I seem to have hit a hitch in getting it to work as expected.

In my detail view, I have a small simple form:
    <form class="inline" action="/app/action/" method="POST">
    {% csrf_token %}
       
<button type="submit">Prepare</button>
   
</form>


My main list view and detail view are class based views, with me attempting to use a FBV for prepare because it seems simpler to understand. I've put a breakpoint in the "action" view, and tried to inspect the request and see data from clicking the button come through, but I don't see it. I am clearly missing something about how django sends POST data. I have tried adding the following in bold to see how to get the data through, as well as adding *args, **kwargs, as well as positional and named keyword arguments to my "action" FBV:

    <form class="inline" action="/app/action/" method="POST" id="{{ obj.id }}" objid="{{ obj.id }}">
    {% csrf_token %}
       
{{obj.id}}
       
<input type="hidden" value="{{obj.id}}" />
       
<button type="submit">Prepare</button>
   
</form>

If anyone can explain what I'm missing, it'd be greatly appreciated!

Vimarsh Chaturvedi

unread,
Nov 29, 2016, 2:07:37 AM11/29/16
to Django users
Hey Jordan, 

Please share your views.py as well. 

Daniel Roseman

unread,
Nov 29, 2016, 3:45:08 AM11/29/16
to Django users
The problem is in your html. Browsers can only send data for inputs with a `name` attribute, which Django then uses as the key in the querydict, whereas the `value` attribute becomes the value for that key.

None of your inputs have names. It also doesn't make sense to add the id to the form or standalone; again, the browser just won't do anything with it.
--
DR.

Jordan W

unread,
Dec 1, 2016, 9:51:19 PM12/1/16
to Django users
Daniel, you nailed it! I didn't have the name specified. Adding that makes it propagate through!

KARTHIKEYAN THANIKACHALAM

unread,
Dec 2, 2016, 7:05:14 AM12/2/16
to django...@googlegroups.com
Hi, 
     you have to add name attribute in html file and use same name attribute in request dictionary to get value

--
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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d75827d7-99b8-4f1e-bd4e-dff5dc000b52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages