When making views in django, is it allowable to pass in POST data as context? That is:
def view( request ):
#view operations here
#...
c = Context({
'POST':request.POST,
})
return render_to_response("/templatePath/", c, context_instance=RequestContext(request))
My goal is to maintain data in fields already filled without having to save them to a db. That is, when you click the option to add additional field entries, the data you’ve put in is kept and automatically filled back into the forms. I feel this might be sloppy or perhaps unsafe. Is there any reason this is a bad or unsafe technique? Is there a better way to maintain data?
Although nothing is inherently bad about passing the
request.POSTvariable to the template, everything you’re trying to achieve is already handled by the stereotypical form view. If you go down your current path, you will end up with a buggy version of the recommended way to handle forms in Django.See using a form in a view in the the Django documentation.
In you case, you’ll want to make sure the redirect URL redirects to the same form. See
django.shortcuts.redirect().