1

I want to parse an integer to the url so I build my urls like this(there are 3 url because can have no arguments, the place or the place and an integer)

urlpatterns = [
    url(r'^map/$', geov.map_view, name = "map_view"),
    url(r'^map/(?P<search_place>[^\.]+)/$', geov.map_view, name = "map_view_accurate"),
    url(r'^map/(?P<search_place>[^\.]+)/(?P<digit>\d+)/$', geov.map_view),
]

So in my views I have:

def map_view(request, search_place = None, digit = 0):
    results = {}
    print(digit)
    if search_place is not None:
        query = Place_search.objects.filter(name_lower__icontains=search_place.lower()).order_by("-importance")
        results["query"] = query
    else:
        points = Place.objects.all()
        lon = points.count()

        results["points"]=points
        results["lon"] = lon

    return render_to_response("index.html", results)

But digit is always 0 and the query variable get no elements. If I just go with the second url(Ex:"localhost:8000/map/madrid" it works correctly)

1 Answer 1

1

Your second's url regexp catch what you want to catch by third url, i.e. search place with slash and digit, you should change it to:

urlpatterns = [
    url(r'^map/$', geov.map_view, name = "map_view"),
    url(r'^map/(?P<search_place>[\w-]+)/$', geov.map_view, name = "map_view_accurate"),
    url(r'^map/(?P<search_place>[\w-]+)/(?P<digit>\d+)/$', geov.map_view),
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.