Hello again Ken! Sometimes I wonder how much of the internet runs on your advice.
you can access it directly from request.POST
Thanks!
So … I thought it was being submitted as HTML form data, but I’m not finding it.
Here’s the template. Isn’t that submitting HTML form data? (I think you can ignore the Javascript – I use that to insert and delete rows. That dynamic aspect is the reason I had to write Javascript instead of using a Django Form.)
The view onto that template hardly does anything:
def dynamic_form ( request ):
if request . method == 'POST':
filename = 'dynamic_table.pickle'
with open(filename,'wb') as f:
f.write(
pickle.dumps(request.body) )
return HttpResponseRedirect (
reverse (
'run_make:thank-you ) )
else: return render (
request,
'run_make/dynamic_form.html' )
As you can see, the view now pickles the request.POST
object, so that I can check it out in the REPL. But the result is gibberish. It seems to only contain a CSRF token:
appuser@127:/mnt/django$ python3 ./manage.py shell
Python 3.8.2 (default, Mar 26 2020, 15:53:00)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import pickle
...: filename = '/home/appuser/dynamic_table.pickle'
...: with open(filename,'rb') as file_object:
...: req = pickle.loads( file_object . read () )
...:
In [2]: req
Out[2]: <QueryDict: {'csrfmiddlewaretoken': ['N6YhYNlk8TTp97NykhGBAUrDwsyVQeFi
rMbSRikjKgsH42rVAtQxkZUaMCvlwMHl']}>
So now I have two questions: (1) Is my form data not in fact being delivered, and (2) is the pickling dance overly complex? It would be great if I didn’t have to take the intermediate pickling and unpickling steps, and could instead somehow access objects the webpage creates directly from the REPL.