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

  • Home
  • SEARCH
  • 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 6114063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:55:51+00:00 2026-05-23T14:55:51+00:00

When my page POSTs a form to my Django view, the view returns a

  • 0

When my page POSTs a form to my Django view, the view returns a response with some data but soon I ran into the issue that my views returned data in different formats and different sets of information. I’ve thought of using JSON as a standard format to return my data.

There are two types of statuses, success and failure. When the POST was successful, it just returns success but when it has failed, it returns a sub group called errors which contains a of fields and that field’s error.

Here’s a sample failure response:

{"failure": {
    "errors":[
        {"fieldname": "<fieldname>", 
         "fielderror": "<fielderror>"
        },
        {"fieldname": "<fieldname>", 
         "fielderror": "<fielderror>"
        }]
}}

Here’s a sample success response:

{"success": {
    "data":[
        {"fieldname": "<fieldname>", 
         "fielddata": "<fielddata>"
        },
        {"fieldname": "<fieldname>", 
         "fielddata": "<fielddata>"
        }]
}}

(The success response has data fields because quite often you like to return some data i.e. key of newly created DB record.)

This is what I’ve come up with but so many people using Django out there, I’m wondering whether there is a standard way/more robust of doing this or some module to help with this.

Thanks.

  • 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-23T14:55:52+00:00Added an answer on May 23, 2026 at 2:55 pm

    been there. I wrote the solution my own (since it’s simple. I dont know if theres a module out there for this). This is just a json response wrapper

    from django.utils import simplejson
    from django.http import HttpResponse
    
    class JsonResponse(HttpResponse):
        def __init__(self, data):
            content = simplejson.dumps(data)
            super(JsonResponse, self).__init__(content=content,
                                               mimetype='application/json')
    
    class Success(JsonResponse):
        def __init__(self, something):
            x = something # set your data here
            content = {'success': {'data': x}}
            super(Success, self).__init__(content)
    
    
    class Failure(JsonResponse):
        def __init__(self, something):
            x = something # set your data
            content = {'failures': {'errors': x}}
            super(Failure, self).__init__(content)
    

    something like that. In my case, I make Success and Failure accept a string and a dictionary for arguments (like Success(data)) to make it even easier

    If your structure is quite complex (or youre too lazy too write them manually), write your own wrapper for that complicated structure (so you can create the response with even less typing), and make the Success/Failure accepts that as argument.

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

Sidebar

Related Questions

I'm trying to do some pretty basic form posts with Django, but whenever I
I am using a form to Rate a page. This form posts data to
I have got a form that posts values to a page in a wizard.
I have a html form that posts to a new page on submit. If
I'd like to post some form variables into a classic ASP page. I don't
I'm building my first form with django, and I'm seeing some behavior that I
I have a page with a form on it that needs to post to
I have a page which displays a form that a logged-in user can use
I've got a Django-based site that allows users to register (but requires an admin
Am using Django's form for my login page. I want to set focus to

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.