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

The Archive Base Latest Questions

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

I decided to learn Django Forms. For a while now, I have been using

  • 0

I decided to learn Django Forms. For a while now, I have been using HTML forms because it’s hard for me to come to terms with Django Forms.

How could I populate initial data to Django Forms?
Example:

Consider if these models are populated. Contain data.

models.py

class Game(models.Model):
   title = models.CharField()
   genre = models.CharField()

so if I have

view.py

game_list = Game.objects.all()
return render_to_response('template',locals())

so in template.html, I could just:

{% for game in game_list %}
<p> game.title <p> <br /> <p> game.genre <p>

If I want to populate initial data when using HTML forms, this is what I usually do:

    {% for game in game_list %}
    <form action= '/add/' method='POST'>
    <input="text" name="title" value="{{game.title}}" />
    <input="text" name="genre" value="{{game.genre}}" />
    <input type="submit" />

How can I do this in Django Forms?
From what I’ve seen by reading articles online, they do this by overriding using forms.__init__:

class Anyforms(forms.Form):
   super(Anyforms, self).__init__(*args,**kwargs)

I can’t get a hold of how to populate using super. What data do forms get during runtime and how?
Any good links that I could read to get me up and running on wrangling Django Forms?

Is this

<input="text" name="title" value="{{game.title}}" /> 
<input="text" name="genre" value="{{game.genre}}" /> 

equivalent to this?

data = {'title':'{{game.title}}','genre':'{{game.genre}}'} 
form(data) 

Are the variables going to be replaced in template?

  • 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-17T06:14:55+00:00Added an answer on May 17, 2026 at 6:14 am

    S. Lott’s answer tells you how to initialize the form with some data in your view. To render your form in a template, see the following section of the django docs which contain a number of examples:

    • Outputting forms as HTML

    Although the examples show the rendering working from a python interpreter, it’s the same thing when performed in a template.

    For example, instead of print f, your template would simply contain: {{ f }} assuming you pass your form through the context as f. Similarly, f.as_p() is written in the template as {{ f.as_p }}. This is described in the django template docs under the Variables section.

    Update (responding to the comments)

    Not exactly, the template notation is only for template. Your form and associated data are initialized in the view.

    So, using your example, your view would contain something like:

    def view(request):
        game = Game.objects.get(id=1) # just an example
        data = {'id': game.id, 'position': game.position}
        form = UserQueueForm(initial=data)
        return render_to_response('my_template.html', {'form': form})
    

    Then your template would have something like:

    {{ form }}
    

    Or if you wanted to customize the HTML yourself:

    {{ form.title }} <br />
    {{ form.genre }} <br />
    

    and so on.

    I recommend trying it and experimenting a little. Then ask a question if you encounter a problem.

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

Sidebar

Related Questions

I have been learning python for some time now. While starting this learning python
I decided to learn LISP today, and have been playing around with it for
I decided to learn C++ (I program in C at work), and I have
I've recently decided that I just have to finally learn C/C++, and there is
I decided to learn HTML so I installed apache on windows vista. Everything seems
I'm a Mac user and I've decided to learn Emacs. I've read that to
I'm an old (but not too old) Java programmer, that decided to learn C++.
I decide to learn more about vim and its syntax highlighting. Using examples for
I decided to make a system for a client using Castle ActiveRecord , everything
I decided to learn Assembly language. The main reason to do so is being

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.