On Thursday, 10 October 2013 20:29:32 UTC+1, ke1g wrote:
-- 2. Write a custom template filter that lets you supply an argumentNo. You can't pass an argument to a model method from the template. I see two options for you:1. Rework the method so that the argument is optional, and if the argument is not provided, the method uses a reasonable default (maybe item.product?).
These answers all miss the point. The main problem is not that you need to pass an argument, it's that what you're trying to do makes *no sense at all* in the context of a template.
You can't make the href of a link just point to a model method. A link needs to be a URL. So it needs a view, and an entry in the urlconf pointing to that view. That urlconf entry, of course, can take an argument, but that argument can't be a "product", it needs to be some kind of ID or slug that can be represented in the URL.
Once you've got the view and the URL, you can use the `{% url %}` tag to generate the value for your link:
<a href="{% url "remove_single" item.id %}">
(although note that an action that removes an item should be a POST, not a simple GET link).
--
DR.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/acd5df91-ac8d-4141-a6fc-ccf4447b6b8d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment