Reputation: 2026
I've assigned form to be request.POST and request.FILES below
But how then do I access the field values. E.g. in the request.post, we have a field called title, how do I get to it?
THanks
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
i=0
title = request.GET.get('title')
version = request.GET.get('version')
Upvotes: 0
Views: 78
Reputation: 159
data = request.POST.copy()
Then you can use data to access the user's submitted data.
To get data from a specific field, use what is set in the name attribute to call the field. This is not always the same as id. Use .get() to access the field, because if the field is left empty in the form, it will not be in data, and None will be returned.
Upvotes: 0
Reputation: 2383
Seeing as you already used form.is_valid()
, I will recommend using cleaned_data
to retrieve the information.
For example:
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password')
Upvotes: 1