python - How to get data from HTML? -
i use django-autocomplete. there 2 fields: first tag-search uses autocomplete , second full-text search. full-text search works, tag search not.
here code of web-page:
<div class="content-section-a"> <div class="container"> <div class="row"> <div class="col-lg-12"> <form action="" method="get"> <p> <span id="id_tag_query-wrapper" class=" autocomplete-light-widget tag_query single" data-widget-bootstrap="normal" data-widget-maximum-values="1" data-widget-ready="1"> <span id="id_tag_query-deck" class="deck" style="display: inline;"> <span data-value="12" class="hilight"> <span style="display: inline-block;" class="remove"> ˣ </span> android </span> </span> <input type="text" name="tag_query-autocomplete" id="id_tag_query-autocomplete" value="" class="form-control autocomplete vtextfield" data-autocomplete-choice-selector="[data-value]" data-autocomplete-url="/autocomplete/tagautocomplete/" placeholder="tag search" autocomplete="off" style="display: none;"> <select style="display:none" class="value-select" name="tag_query" id="id_tag_query" multiple="multiple"> <option selected="selected" value="12"></option></select> <span style="display:none" class="remove">ˣ</span> <span style="display:none" class="choice-template"> <span class="choice prepend-remove append-option-html"></span> </span> </span> </p> <div class="input-group"> <input type="text" class="form-control" name="search" placeholder="search"> <span class="input-group-btn"> <button type="submit" class="btn btn-default" value="search"> search </button> </span> </div> </form> </div> </div> </div> </div>
view:
class threadsview(listview): model = thread def get(self, request, *args, **kwargs): form = tagform(request.get) if request.get.get('search'): search_results = watson.search(request.get.get('search')) threads = [] in search_results: threads.append(i) c = requestcontext(request, {'search_list': threads}) if request.get.get('id_tag_query-deck'): search_results = watson.search(request.get.get('id_tag_query-deck')) threads = [] in search_results: threads.append(i) c = requestcontext(request, {'search_list': threads}) else: threads = thread.objects.all() c = requestcontext(request, {'threads_list': threads, 'form': form}) return render_to_response('threads.html', context_instance=c)
form:
class tagform(forms.form): tag_query = autocomplete_light.fields.choicefield( choices=(tuple((tag.name, tag.name) tag in tag.objects.all())), required=false, label='', widget=autocomplete_light.widgets.choicewidget( 'tagautocomplete', attrs={ 'class':'form-control', 'placeholder':'tag search' } ) )
request.get.get('id_tag_query-deck'):
false, need use name
attribute of input, passing id
attribute of span
perhaps
request.get.get('tag_query-autocomplete')
or request.get.get('tag_query')
give value want -- depends on field want. use name
of input
looking for.
Comments
Post a Comment