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 288849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:51:14+00:00 2026-05-12T05:51:14+00:00

I have a form ‘in the wild’ that takes many different variables – which

  • 0

I have a form ‘in the wild’ that takes many different variables – which may or may not be populated.

   try:
        app_version = request.REQUEST["appVersion"]
    except:
        app_version = ''

    try:
        app_name = request.REQUEST["appName"]
    except:
        app_name = ''

    try:
        app_code_name = request.REQUEST["appCodeName"]
    except:
        app_code_name = ''

Is there a tighter way to accomplish this?

  • 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-12T05:51:14+00:00Added an answer on May 12, 2026 at 5:51 am

    If these variables are intended to populate a form, then you can safely pass the request.POST object directly into the form constructor.

    if request.method == 'POST':
        form = MyForm(request.POST)
    

    The form will automatically pass the correct values to the correct form fields and use defaults for keys that don’t exist and will still create blank fields for missing keys (see addendum).

    If you are trying to process a form, it is still better to create a form object as above, and read out the values from that object.

    if request.method == 'POST':
        form = MyForm(request.POST)
        if form.is_valid():
            # You may process these variables here
            print form.appVersion
            print form.appName
            print form.appCodeName
    

    Remember, validation code is best placed in the form class as well. That way, if form.is_valid() returns True, then you know you have a clean dataset to work with.

    Note: Django docs recommend using request.POST or request.GET directly rather than the amalgamated variable request.REQUEST, as it is more explicit.

    Addendum:

    It is important to understand the difference between bound and unbound forms in this case. If you create an unbound form with form = MyForm(), then when the form is instantiated, it will fill in all fields with the initial property of each field (if it exists). For example, with this code:

    from django import forms
    
    class MyForm(forms.Form):
        appVersion = forms.CharField(initial='1.0')
        appName = forms.CharField()
        appCodeName = forms.CharField()
    

    the form will be initialized with appVersion having a value of ‘1.0’. However, if you bind a POST request to a form like this: form = MyForm(request.POST), then the initial properties are ignored. That means if the POST dict does not include an appVersion key, then that field will be left blank. As long as the field is not required, your form will still validate, and you can modify form.appVersion in the view after validation.

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

Sidebar

Related Questions

I have a form that contains a GridView control which is databound to an
I have form that displays several keywords (standard set of choice lists that changes
I have a form in C# that has a button that, when clicked, I
I have subclassed Form to include some extra functionality, which boils down to a
I have a form with some radio buttons that are disabled by default. When
I have a form with many input fields. When I catch the submit form
I have a form in which people will be entering dollar values. Possible inputs:
I have a form element that contains multiple lines of inputs. Think of each
I have form, which i dont want the user to see it. Dont ask
I have a form which contains 4 text fields when the button is clicked

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.