In my Django application, I need to access what the user filled in the City text field.
This is the city text field from the template:
<label class="reglabel">City: </label><br>
{{ profile_form.city|add_class:"input-md textfields" | attr:"placeholder: Search Cities..."|attr:"id:searchBoxGlow" | attr:"name: cityname" }}
{{ profile_form.city.errors }}<br>
In my View.py file I try to access the value using the name attribute I added to the template:
print request.POST.get("cityname", "")
I followed advice from this question:
Django - taking values from POST request
This is the form, at this stage I just want to pull the text the user fills so I can turn it into a city instance and save the form.
class UserProfileForm(forms.ModelForm):
city = forms.CharField(required=True)
class Meta:
model = UserProfile
fields = ('profilepic', 'city', 'hobbies', 'languages')
However, it prints blank instead of what the user filled in the City text field.