我正在使用带有django的google map的python客户端库。我希望有人输入时可以使用建议地址的下拉菜单。有什么建议吗?
urls.py
urlpatterns = [
path('', views.index, name='index'),]
forms.py
from django import forms
class distance(forms.Form):
pickupAddress = forms.Field(label='pickup address')
destAddress = forms.Field(label='destination address')
view.py
import googlemaps
from .form import distance
gmaps = googlemaps.Client(key='*****')
distance = gmaps.distance_matrix(pickupAddress, destAddress)
return render(request, 'index.html', {'form': form, 'distance':distance)
index.html
{% load crispy_forms_tags %}
<form action="" method="post">
{% csrf_token %}
<table>
{{ form|crispy }}
</table>
<input type="submit" value="Submit" />
</form>
<ul> <strong> distance:</strong>{{ distance }}</ul>