私は Pyusps(Python USPS Api) を使用して、住所が実際に存在するかどうかを確認しています。データをキャプチャするフォームを作成しました。API からデータを受信して次のページに表示するのに苦労しています。どんな助けでも大歓迎です。
#views.py
def address(args):
address = AddressForm['street']
def city(args):
city = AddressForm['city']
def state(args):
state = AddressForm['state']
def zip5(args):
zip5 = AddressForm['zip_code']
def address_view(request):
if request.method == 'POST':
form = AddressForm(request.POST)
if form.is_valid():
try:
from pyusps import address_information
addr = dict([
('address', {'address': address}),
('city', {'city': city}),
('state', {'state': state}),
('zip5', {'zip_code': zip5}),
])
address_information.verify('API_ID', addr)
a = dict([
('address', '6406 IVY LN'),
('city', 'GREENBELT'),
('state', 'MD'),
('zip5', '20770'),
('zip4', '1441'),
])
c = {'form': a}
return render_to_response('address_change.html', c, context_instance=RequestContext(request))
except ValueError:
pass
else:
form = AddressForm()
c = {'form': form}
return render_to_response('address_change.html', c, context_instance=RequestContext(request))
#models.py
class Address(models.Model):
user = models.ForeignKey(User)
street = models.CharField(max_length=50)
city = models.CharField(max_length=50)
state = models.CharField(max_length=50)
zip_code = models.CharField(max_length=50)
# Pyusps API Documentation
from pyusps import address_information
addr = dict([
('address', '6406 Ivy Lane'),
('city', 'Greenbelt'),
('state', 'MD'),
])
address_information.verify('foo_id', addr)
dict([
('address', '6406 IVY LN'),
('city', 'GREENBELT'),
('state', 'MD'),
('zip5', '20770'),
('zip4', '1441'),
])