TypeError save() takes at least 2 non-keyword arguments (1 given)
i have in my views.py
def status_set(request):
ip_address= request.META['REMOTE_ADDR']
if request.method == "POST":
rform = registerForm(data = request.POST)
if rform.is_valid():
register = rform.save(commit=False)
register.user=request.user
register.save()
return render_to_response('home.html')
else:
rform = registerForm()
return render_to_response('status_set.html',{'rform':rform})
and in forms.py ihave
from django.contrib.gis.utils import GeoIP
class registerForm(forms.ModelForm):
class Meta:
model=register
fields = ('Availability', 'Status')
def save(self,ip_address, *args, **kwargs):
g = GeoIP()
lat, lon = g.lat_lon('ip_address')
user_location = super(registerForm, self).save(commit=False)
user_location.latitude = lat
user_location.longitude = lon
user_location.save(*args, **kwargs)
开发者_如何学运维
and when i tried to submitt the form it says
TypeError at /status-set/ save() takes at least 2 non-keyword arguments (1 given) iam unable to find the solution for that. what is the possible reason for this i think i have to pass the ip address as an argument any suggestions
The ip_address parameter is required so you must provide it:
register.save(ip_address)
Also, you don't actually appear to be using the ip_address parameter inside the method. Probably you should not have quotes aroung ip_address
in the method you are calling:
lat, lon = g.lat_lon(ip_address)
精彩评论