Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » render_to_response format using forms [RSS Feed]

#1 Jan. 7, 2011 15:15:38

h.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

render_to_response format using forms


In the topics forms documentation there's an example of using a form
in a view which shows a return statement using a render_to_respone
shortcut like this:

return render_to_response('contact.html', {
'form': form,
})

but in the shortcuts documentation it shows an example of using
render_to_response not using forms and coded like this:

return render_to_response('my_template.html',
my_data_dictionary,

context_instance=RequestContect(request))

So if I want to use a form when coding a view how do I merge or
reconcile these two different examples so that my render_to_repsonse
will work properly? Please advise. Thanks.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 7, 2011 15:27:31

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

render_to_response format using forms


On Friday, January 7, 2011 3:15:33 PM UTC, hank23 wrote:
>
> In the topics forms documentation there's an example of using a form
> in a view which shows a return statement using a render_to_respone
> shortcut like this:
>
> return render_to_response('contact.html', {
> 'form': form,
> })
>
> but in the shortcuts documentation it shows an example of using
> render_to_response not using forms and coded like this:
>
> return render_to_response('my_template.html',
> my_data_dictionary,
>
> context_instance=RequestContect(request))
>
> So if I want to use a form when coding a view how do I merge or
> reconcile these two different examples so that my render_to_repsonse
> will work properly? Please advise. Thanks.


These are not substantially different, and the minor differences have
nothing to do with forms. The only difference is that one is using the
additional context_instance argument, for which see here:http://docs.djangoproject.com/en/1.2/ref/templates/api/#subclassing-context-requestcontextbut as I say, this has nothing to do with forms. Apart from using a literal
dictionary instead of a variable containing a dictionary, there is no other
difference between the two examples.
--
DR.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 7, 2011 15:38:19

h.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

render_to_response format using forms


So then when using a form do I code it something like this then:


return render_to_response('contact.html', {
'form': form,
my_data_dictionary,
context_instance=RequestContext(request))

})


I ask because it's confusing me when using a form for how to code the
form reference while still including the dictionary and context
references. The dictionary reference almost seems redundant since when
I go to create my form and assign it the name form I use the data
dictionary in the constructor of my form. Please clarify.


On Jan 7, 9:27 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Friday, January 7, 2011 3:15:33 PM UTC, hank23 wrote:
>
> > In the topics forms documentation there's an example of using a form
> > in a view which shows a return statement using a render_to_respone
> > shortcut like this:
>
> > return render_to_response('contact.html', {
> >      'form': form,
> > })
>
> > but in the shortcuts documentation it shows an example of using
> > render_to_response not using forms and coded like this:
>
> > return render_to_response('my_template.html',
> >                                        my_data_dictionary,
>
> > context_instance=RequestContect(request))
>
> > So if I want to use a form when coding a view how do I merge or
> > reconcile these two different examples so that my render_to_repsonse
> > will work properly? Please advise. Thanks.
>
> These are not substantially different, and the minor differences have
> nothing to do with forms. The only difference is that one is using the
> additional context_instance argument, for which see
> here:http://docs.djangoproject.com/en/1.2/ref/templates/api/#subclassing-c...
> but as I say, this has nothing to do with forms. Apart from using a literal
> dictionary instead of a variable containing a dictionary, there is no other
> difference between the two examples.
> --
> DR.- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Jan. 7, 2011 15:43:09

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

render_to_response format using forms


On Friday, January 7, 2011 3:38:10 PM UTC, hank23 wrote:
>
> So then when using a form do I code it something like this then:
>
>
> return render_to_response('contact.html', {
> 'form': form,
> my_data_dictionary,
> context_instance=RequestContext(request))
>
> })
>
>
> I ask because it's confusing me when using a form for how to code the
> form reference while still including the dictionary and context
> references. The dictionary reference almost seems redundant since when
> I go to create my form and assign it the name form I use the data
> dictionary in the constructor of my form. Please clarify.
>


No, for some reason you're thinking of the form as something special. It's
not - it's simply part of the context, just like anything else you pass to
the template. So the form just goes inside `my_data_dictionary` along with
any other data you want there.
--
DR.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Jan. 7, 2011 15:57:33

h.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

render_to_response format using forms


I see. So then I would code it something like this then:

return render_to_response('contact.html',
{ my_data_dictionary(including an entry for 'form': form) },
context_instance=RequestContext(request))




On Jan 7, 9:42 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Friday, January 7, 2011 3:38:10 PM UTC, hank23 wrote:
>
> > So then when using a form do I code it something like this then:
>
> > return render_to_response('contact.html', {
> >      'form': form,
> >      my_data_dictionary,
> >      context_instance=RequestContext(request))
>
> > })
>
> > I ask because it's confusing me when using a form for how to code the
> > form reference while still including the dictionary and context
> > references. The dictionary reference almost seems redundant since when
> > I go to create my form and assign it the name form I use the data
> > dictionary in the constructor of my form. Please clarify.
>
> No, for some reason you're thinking of the form as something special. It's
> not - it's simply part of the context, just like anything else you pass to
> the template. So the form just goes inside `my_data_dictionary` along with
> any other data you want there.
> --
> DR.- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 Jan. 7, 2011 16:05:32

h.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

render_to_response format using forms


Another question about forms. So the form name or names that I pass in
the dictionary to the response can also be named anything and aren't
required to be of a specific form name format right?


On Jan 7, 9:57 am, hank23 <hversem...@stchas.edu> wrote:
> I see. So then I would code it something like this then:
>
> return render_to_response('contact.html',
>     { my_data_dictionary(including an entry for 'form': form) },
>     context_instance=RequestContext(request))
>
> On Jan 7, 9:42 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
>
>
>
> > On Friday, January 7, 2011 3:38:10 PM UTC, hank23 wrote:
>
> > > So then when using a form do I code it something like this then:
>
> > > return render_to_response('contact.html', {
> > >      'form': form,
> > >      my_data_dictionary,
> > >      context_instance=RequestContext(request))
>
> > > })
>
> > > I ask because it's confusing me when using a form for how to code the
> > > form reference while still including the dictionary and context
> > > references. The dictionary reference almost seems redundant since when
> > > I go to create my form and assign it the name form I use the data
> > > dictionary in the constructor of my form. Please clarify.
>
> > No, for some reason you're thinking of the form as something special. It's
> > not - it's simply part of the context, just like anything else you pass to
> > the template. So the form just goes inside `my_data_dictionary` along with
> > any other data you want there.
> > --
> > DR.- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#7 Jan. 7, 2011 17:03:27

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

render_to_response format using forms


On Friday, January 7, 2011 4:05:27 PM UTC, hank23 wrote:
>
> Another question about forms. So the form name or names that I pass in
> the dictionary to the response can also be named anything and aren't
> required to be of a specific form name format right?
>

Yes, that's correct. There's no name-based magic - it all follows the Python
dictum "explicit is better than implicit".
--
DR.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » render_to_response format using forms [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support