Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7410839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:17:41+00:00 2026-05-29T06:17:41+00:00

I have a simple Django-Piston Handler that creates a new instance of a model

  • 0

I have a simple Django-Piston Handler that creates a new instance of a model and saves it.

From the client, I am posting using Javascript Objects and JQuery.post.

Upon inspecting the data with Firebug, the post string looks like this:

classification=&organization=&title=Formatting+Test+7&description=test&created_by=created_on=&last_modified=&csrfmiddlewaretoken=a8352bb51f88c271119a81228a5c291f

As you can see, only title, description, and csrfmiddlewaretoken are set.

Inside the Piston Handler, at the top of the create method before any other code is run, I print out the request.POST:

print 'POST:', request.POST

Which prints the following in the Django Dev Server output:

POST: <QueryDict: {u'description': [u'test'], u'classification': [u''], u'title': [u'Formatting Test 7'], u'created_by': [u''], u'created_on': [u''], u'last_modified': [u''], u'organization': [u''], u'csrfmiddlewaretoken': [u'a8352bb51f88c271119a81228a5c291f']}>

As you can see, all of the data is in lists now. When I save the data using a Django Form, it converts the list to a string and when the data shows up on the client, instead of “Formatting Test 7”, it displays “[u’Formatting Test 7′]”.

Googling doesn’t seem to return anyone with the same problem, and I have been using Piston for over 6 months and I have never seen an error like this before.

EDIT: As JPIC said, the error I thought I was experiencing was not an error, but by design. My problem was in extending the data in the QuerySet before I used it with a Django Form.

The Wrong Way:

some_initial_data = {
    'created_by': creator.pk, 
    'organization': org.pk,
    'classification': 7
} 
post = dict(request.POST)
post.update(some_initial_data)
form = MyModelForm(post)

The Right Way:

As described in the update method for QueryDict: https://docs.djangoproject.com/en/1.3/ref/request-response/#querydict-objects

some_initial_data = {
    'created_by': creator.pk,
    'organization': org.pk,
    'classification': 7
}
post = request.POST.copy()
post.update(initial_data)
form = MyModelForm(post)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:17:42+00:00Added an answer on May 29, 2026 at 6:17 am

    It is not an error, your data has always been in such a list, it is a design decision from Django. Whatever code is accessing the QueryDict instance and gets list values otherwise than with the getlist() method is using QueryDict wrong.

    QueryDict allows multiple values for a key ie.: foo=bar&foo=test your QueryDict will be like {u'foo': [u'bar', u'test']}.

    Example with ?foo=bar&foo=test&x=y:

    ipdb> request.GET
    <QueryDict: {u'x': [u'y'], u'foo': [u'bar', u'test']}>
    ipdb> request.GET['x']
    u'y'
    ipdb> request.GET.getlist('x')
    [u'y']
    ipdb> request.GET['foo']
    u'test'
    ipdb> request.GET.getlist('foo')
    [u'bar', u'test']
    

    As you can see, QueryDict is a dict of lists which won’t resort to the actual lists by default: it will act like a normal dict. So if some code is getting the list then it’s using the QueryDict wrong.

    One thing worth mentionning is that if you want to use $.post(url, {'foo':['bar', 'test']}) then you will need to call $.ajaxSettings.traditional = true !

    This is useful for example with checkboxes or multiple-selects. Correct me if I’m wrong but this is standard, and the PHP way foo[]=bar&foo[]=test is not standard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple django app that is using only the admin. This is
I currently have a simple model defined, with a photoupload feature using django thumbnails
I have a simple question. using the example from django above. How can i
I have a simple Django view that just returns URL parameters, but if I
I have a simple django page that has a counter on it. I use
I'm using django-piston for my REST json api, and I have it all set
I have a simple Python/Django class: class myModel(models.Model): date = models.DateTimeField() value = models.IntegerField()
I'm new to django. I have 2 simple objects, lets call them - File
I have a pretty simple form: from django import forms class InitialSignupForm(forms.Form): email =
I have this simple form: class PagoDesde(forms.Form): from django import forms as f desde

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.