The problem is that if a URL pattern requires extra info after the
path, my templates don't render, because the extra parameters aren't
known until the user makes a selection.
The obvious solution is to make two URL patterns for each of these
URLs -- one with no extra parameters and one with. Then change the
former into the latter in the app by AJAX.
Is there a better way to do this?
Example:
#urls.py:
url(r'^update_payment/(?P<payment_id>\w+)', update_payment, name =
'update_payment'),
#template:
<a href="{% url update_payment %}">Update Payment</a> {# this
expects a second argument I don't know yet #}
Thanks,
Shawn
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Ryan,
Thanks. I considered that first, but rejected it because I want the
extra field to be required. If it's missing then it's an error. Giving
it a default in the view definition means extra code in all effected
views, which isn't DRY. Also a bug caused by missing parameters that
cause an error is more subtle than the (admittedly ugly) "duplicate"
url pattern.
I was hoping that, since the url tag, named URLs, and URLs with extra
parameters are all baked-in parts of Django that Django would have a
canonical way to deal with this, since URLs built based on user
actions are a very old technique. It seems like someone must have run
into this before me.
It occurs to me now that I could just use a placeholder, and replace
that in JavaScript:
<a href="{% url update_payment 'payment_id' %}">Update Payment</a>
Then use the JavaScript to replace the string 'payment_id' (or a regex
on its location in the URL) when the user takes action. It also moves
all of the logic out of views and urls, which I think is probably
best.
Shawn