所以我的问题是结果随即吐出:
1980 Mission Street,旧金山,加利福尼亚州,美国
...但我需要它给我邮政编码,因为当我把它放回谷歌的地理编码器时,由于某种原因它没有注册位置.
//这是我只有自动完成输入字段的代码
var input = document.getElementById('id_address');
var options = {
types: ['address'],
componentRestrictions: {country:'us'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
Run Code Online (Sandbox Code Playgroud)
//这就是我使用地理编码器的方式
window.onload = function initMap() {
console.log("{{ task.address }}");
console.log("{{ location }}");
var address = "{{ location }}";
geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function(results, status) {
<!-- console.log(address); -->
if (status == google.maps.GeocoderStatus.OK) {
var map = new google.maps.Map(document.getElementById('map'), {
center: results[0].geometry.location,
zoom: 12,
});
var marker = new google.maps.Marker({
map: map,
position: …Run Code Online (Sandbox Code Playgroud) 我有点困惑为什么它不断返回“输入有效日期”消息。是我的格式问题吗?
我尝试过 %m-%d-%Y 的不同组合,但仍然没有成功。
模型.py
class DeliveryDate(models.Model):
cart = models.ForeignKey('Cart', null=True, blank=True)
date = models.DateField()
def __str__(self):
return str(self.cart.id)
return self.date
Run Code Online (Sandbox Code Playgroud)
视图.py
def add_delivery_date(request):
the_id = request.session['cart_id']
cart = Cart.objects.get(id=the_id)
form = DeliveryDateForm(request.POST or None)
if request.method == "POST":
if form.is_valid():
delivery_date = form.save(commit=False)
date = request.POST['date']
delivery_date = DeliveryDate.objects.create(cart=cart, date=date)
delivery_date.save()
return HttpResponseRedirect('thank-you.html')
context = {
"form": form
}
return render(request, 'choose_delivery_date.html', context)
Run Code Online (Sandbox Code Playgroud)
表格.py
class DeliveryDateForm(forms.ModelForm):
date = forms.DateField(input_formats=['%m %d %Y'], widget=SelectDateWidget, initial=datetime.date.today())
class Meta:
model = DeliveryDate
fields …Run Code Online (Sandbox Code Playgroud)