(Help Me !) How to extract name attribute of <input> element from instantiated form object inside views.py

17 views
Skip to first unread message

Mayur Bagul

unread,
May 6, 2019, 8:41:46 AM5/6/19
to Django users
Hello Community,

I've been stuck to this problem from one week. I have read Django Doc. and i found little bit relevant to my problem.

Form.py 


from django import forms

class NameForm(forms.Form):
    city_name = forms.CharField(label='city name', max_length=100)
 


Views.py



from django.http import HttpResponseRedirect
from django.shortcuts import render

from .forms import NameForm

def get_name(request):
  
    if request.method == 'POST':
        
        form = NameForm(request.POST)
      
      # Here i wanted to extract value stored inside Text Box  How i can do that?

     #i wanted to extract city entered by user and store into another variable how to do it?

     # i wanted to use that variable to put it for filter 


                   info = Data.objects.filter(city__exact='city'
                   
                   above line is for retrieving  record for entered city from database.


       return render(request, 'name.html', {'info': info}) 

    else:
        form = NameForm()

    return render(request, 'name.html', {'form': form})




Please help me with this guys !

i really need help on this because im not getting syntax for this on any resource.

Thanking you.

salimon jamiu olashile

unread,
May 6, 2019, 9:31:07 AM5/6/19
to django...@googlegroups.com
use this to access the city_name field value;

form.cleaned_data[“city_name”]

Use to a print statement to see for yourself.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/666102fa-661e-4330-97f1-1414d7b08bce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mayur Bagul

unread,
May 6, 2019, 12:07:59 PM5/6/19
to Django users
thanks !


for solution it will be helpful to me.


On Monday, May 6, 2019 at 7:01:07 PM UTC+5:30, Jamiu Olashile Salimon wrote:
use this to access the city_name field value;

form.cleaned_data[“city_name”]

Use to a print statement to see for yourself.

To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

salimon jamiu olashile

unread,
May 6, 2019, 12:27:23 PM5/6/19
to django...@googlegroups.com
You’re welcome 

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages