Python Django Getting user input -


i setting simple html page, page captures information user entered , based on information user entered makes new page. problem cant information entered user @ backed , dont understand going wrong.

my views file setup this:

def suggestion(request):       if request.method == 'post':         form = businessname(request.post)         if form.is_valid():             data=form.cleaned_data               context = insert_function_here(data)             return render( request,'mainpage.html', context)     else:         form = businessname()           context = {'form':form}         return render( request,'mainpage.html', context)  

my forms.py setup this:

class businessname(forms.form):     business_name = forms.charfield(widget = forms.hiddeninput(), required = false) 

the relevant part of html set this:

<form id="user_input_form" method="post" action="http://127.0.0.1:8000/textinsighters/suggestion">     enter business name : <input type="text" list="browsers" name="browser" id="user_input">     {% csrf_token %}     {{ form }}       <datalist id="browsers">         <option value="internet explorer">         <option value="firefox">         <option value="chrome">         <option value="opera">         <option value="safari">       </datalist>       <button onclick="myfunction()">submittt</button> </form> <script>     function myfunction() { document.getelementbyid("id_business_name").value = document.getelementbyid("user_input").value;                                             document.getelementbyid("user_input_form").submit();     } </script> 

i want auto-completing list thats why creating form in html. user input, set value of django form field value user entered , submit it. should variable 'data' in views doesnt contain user input.

thanks

you using forms.hiddeninput() widget , add form field yourself. doesn't work way. if change field class textinput:

class businessname(forms.form):     business_name = forms.charfield(widget = forms.textinput()) 

if you're goal add custom attributes widget, can done providing attrs dictionary:

class businessname(forms.form):     business_name = forms.charfield(widget = forms.textinput(attrs={         'list': 'browser'     })) 

or have @ django-widget-tweaks package add attributes in template.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)