[Answer]-Passing a variable from template in Django

1👍

For specific country which will take id and name of country you can define the URL pattern as:

url(r'^country/(?P<id>\d+)/(?P<name>\w+)' , 'wiki.views.country', name='wiki_country'),

The view will be:

def country(request, id, name):
    country = Country.objects.get(id=id, name=name)
    return render_to_response("wiki/country.html", {'country': country})

In listing template you can have a link as:

{% for country in countries %}
    <a href="{% url 'wiki_country' country.id country.name %}">{{ country.name }}</a>
{% endfor %}

Hope this will lead you somewhere.

Leave a comment