First of all what you have written will most likely give syntax error,
in your dict you have reversed the key and value. You probably want it
to look like this: {"username": thisusername}. But you can't just
throw random data at forms and hope for it to work. There are some
different solutions, but if all you want to dø is to write hallo
username, you dont even need to do anything with forms, unless you
want the username to be displayed in an input field when the form
loads. Remember, django forms are not forms, but form elements. You
still have to suply the form and input tags yourself and thus can
write hallo username or whatever inside the form if you want it as an
headline or something else.

~Jakob

On 16 Mar., 20:14, NoviceSortOf <dljonsson2...@gmail.com> wrote:
> Thanks for your responses, they have helped.
>
> I've read the documentation many times, and only resort to groups
> after re-reading what I can find in the docs, testing various logical
> solutions, digging through groups and finally confering with a 3rd
> party book I've here on Django. If all else fails,
> then I post to groups.
>
> So that is why I'm puzzled when {{ var }} does not present var on my
> form.
>
> As mentioned above in views.py I'm passing data to the form_class in
> this example I'm using str to convert value to string.
>
> in view.py then
> ...
> thisusername = str(request.user.username)
> data = {'thisusername':username,}
> form = form_class(data)
>
> Now it seems form_class() would be adding the data to
> itself with form_class(data) but it isn't.
>
> Instead I have to add the context to the render_to_response
> despite the fact that this data has been added to form
> earlier.
>
> ie.
> return render_to_response(template_name, { 'form': form},
>                               context_instance=context)
>
> will either not display the item, or force it to be viewed
> only as a corresponding writable field as defined in forms.py
> or model.py.
>
> but loading it directly to render_to_response works...
>
> return render_to_response(template_name, { 'form': form,
> 'thisusername':username},
> context_instance=context)
>
> 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?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to