Answer the question
In order to leave comments, you need to log in
How to access data entered by the user into a form?
I do not understand how to get the data that I collected from the forms?
In the documentation, an example, as I understand it, in HttpResponseRedirect, instead of /thanks/ there should be a link where I redirect the data received via request.POST from the form. But I'm not passing the variable itself, I'm just doing a redirect? How can I display this data from forms in the new template (/thanks/) - call another function in urls, but how can I pass data from forms to it, its scope is limited by its own limits?
view.py
from .forms import NameForm
def get_name(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = NameForm(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect('/thanks/')
else:
form = NameForm()
return render(request, 'name.html', {'form': form})
Answer the question
In order to leave comments, you need to log in
That is, on the server, after receiving the POST, do you want to redirect to another page / controller and there so that there is data?
This is possible only with saving data to the database (the application context will not be useful here).
By the way, an interesting question. It's a crazy idea to throw in the cache, on /thanks/ pull from the cache and delete. Instead of a cache, you can use redis as a buffer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question