I like the idea of ββAnatoly, but I think using a certain integer is dangerous. Usually I want to specify the name of an id object, which should always be positive, so I just use negative integers as placeholders. Does this mean adding -? to a URL definition, for example:
url(r'^events/(?P<event_id>-?\d+)/$', events.views.event_details),
Then I can get the reverse url in the template by writing
{% url 'events.views.event_details' event_id=-1 %}
And use replace in javascript to replace placeholder -1 , so in the template I would write something like
<script type="text/javascript"> var actual_event_id = 123; var url = "{% url 'events.views.event_details' event_id=-1 %}".replace('-1', actual_event_id); </script>
This easily extends to several arguments, and the mapping for a particular argument is visible directly in the template.
leifdenby Oct 23 '13 at 15:12 2013-10-23 15:12
source share