문제

So I have this line of code in views.py

def display_agao(request):
    query_agao = Butuan_Parcel.objects.filter(newpin="162-01-0001-002-29")
    djf = Django.Django(geodjango='geom',properties=['id','newpin'])
    geoj = GeoJSON.GeoJSON()
    butuan_agao = geoj.encode(djf.decode(query_agao.transform(3857)))

    query_subclass = tbl_subclass.objects.all()
    return render(request,"index1.html",{'butuan_agao': butuan_agao, 'query_agao':query_agao,'query_subclass':query_subclass})

I want to get the value from the html file and so that I can get a newpin depends on the users query and able to display the layer from the map..

    <form action="." method="GET">
            <select name="q">
             {% for parcel in query_agao %}
            <option type="text"  value="{{ parcel.newpin }}">{{ parcel.newpin }}</option>
             {% endfor %}
              </select>
              <input type="submit" value="Search">

        </form>

just sample form above...

도움이 되었습니까?

해결책

You can get the value from html form to view use request arg,

def my_view(request, ):
   search_term = request.GET.get("q", None) #--> q means "name" of select box in html.
   # use search_term whatever you wants.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top