0

我有意见.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}) 

在 forms.py 我有

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)

当我试图提交它说的表格时

/status-set/save() 处的 TypeError 至少需要 2 个非关键字参数(给定 1 个)我无法找到解决方案。这可能是什么原因我认为我必须将 IP 地址作为参数传递任何建议

4

1 回答 1

2

ip_address 参数是必需的,因此您必须提供它:

register.save(ip_address)

此外,您实际上并没有在方法中使用 ip_address 参数。可能您在调用的方法中不应该有引号ip_address

lat, lon = g.lat_lon(ip_address)
于 2010-11-27T23:36:08.587 回答