在进行增删查的时候都很顺利,但是每次更新都不成功,反而是添加了数据.
@require_http_methods(["GET"])
def update_rock(request):
response = {}
rock_id = request.GET.get('id')
rock_name = request.GET.get('rock_name')
lat = request.GET.get('lat')
lng = request.GET.get('lng')
try:
rock = Rock.objects.get(id=rock_id)
rock.rock_name = rock_name
rock.lat = lat
rock.lng = lng
rock.save()
response['msg'] = 'success'
response['error_num'] = 0
except Exception as e:
response['msg'] = str(e)
response['error_num'] = 1
return JsonResponse(response)
明明代码也没有什么问题.结果发现在urls.py页面:
urlpatterns = [
url(r'add_rock$', add_rock, ),
url(r'update_rock$', add_rock, ),
url(r'show_rocks$', show_rocks, ),
url(r'delete_rock$', delete_rock, ),
]
update_rock导向的函数竟然是add_rock,复制粘贴的时候只改了前面的!
以后得万分注意.