无法解析余数:'-save'来自'waypoints-save'

时间:2015-08-04 17:30:30

标签: django geodjango

我正在按照http://invisibleroads.com/tutorials/geodjango-googlemaps-build.html在geodjango中尝试一个简单的应用。 我的视图功能是

 # Import django modules
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template.loader import render_to_string
# Import system modules
import json
# Import custom modules
from waypoints.models import Waypoint


def save(request):
    'Save waypoints'
    for waypointString in request.POST.get('waypointsPayload', '').splitlines():
        waypointID, waypointX, waypointY = waypointString.split()
        waypoint = Waypoint.objects.get(id=int(waypointID))
        waypoint.geometry.set_x(float(waypointX))
        waypoint.geometry.set_y(float(waypointY))
        waypoint.save()
    return HttpResponse(simplejson.dumps(dict(isOk=1)), mimetype='application/json')

urls.py是

    from django.conf.urls import patterns, include, url


urlpatterns = patterns('waypoints.views',
    url(r'^$', 'index', name='waypoints-index'),
    url(r'^save$', 'save', name='waypoints-save'),
)

显示错误http://dpaste.com/3EJVX0G

模板index.html在这里http://pastebin.com/125Dm6Bz

请帮助我。我是django的新手。

1 个答案:

答案 0 :(得分:1)

{% url %}标记的参数必须始终用引号括起来(如果它是一个文字字符串)(自版本1.5以来就是这种情况,这是很长时间)。

造成错误的是:

$.post("{% url waypoints-save %}"

应该是:

$.post("{% url "waypoints-save" %}"

但你在该模板中多次犯同样的错误。