On Mar 16, 2:14 pm, NoviceSortOf <[email protected]> wrote:
>
> So perhaps a better question would be is
>
> in view.py...
> -----------
> thisusername = str(request.user.username)
> data = {'thisusername':username,}
> form = form_class(data)
>
> Why is it form_class(data) does not accept the data
> as declared and enable it to presented it in
> templates in any other form than a writable field
>  --  when render_to_response allows the data to be
>      presented as a string?

Forms don't work that way. They aren't used to display arbitrary data.
They are used to display form fields. It sounds like you don't want
the username as a form field, you just want it as normal text. You
need to pass non-form field data to the template, in the context
dictionary. Forms should be constructed with data to bind to the form
fields (such as request.POST data) or maybe initial values for the
form fields [1]. Please see:

http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view

and especially:

http://docs.djangoproject.com/en/dev/ref/forms/api/#ref-forms-api

So you'll need something like this (for the non-POST case):

form = MyForm()
username = ...
return render_to_response(template_name,
   { 'form': form,
     'username': username,
   },
   context_instance=context)

And then in your template, this should get you started:

<p>{{ username }}<p>
{{ form.as_p }}

but realize there are many other ways to display a form as the docs
note.

Hope that helps,
BN

[1] Maybe I am missing something but I don't see the initial keyword
argument to the forms.Form class documented?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to