On Wednesday, 1 October 2014 21:35:30 UTC+1, Malik Rumi wrote:
>
> Ok, thank you Daniel. Your response is reasonable and makes sense, but
> that clarity is not on the docs page. But this leads me to a related follow
> up: The need for the parameter, be it 'green' as in my case or '1945' as in
> the docs, means that each template is going to be tied to a single web
> page. So instead of hardcoding the url, we are hardcoding the template,
> meaning it can't be re-used, even if the only difference between it and the
> copy is 'yellow' instead of 'green'.
>
> In other words, two documents in the same namespace, with the same view
> and the same regex/url pattern, can't be reversed unless you include a
> distinguishing, unique parameter in the url tag. And this unique parameter
> has to be 'hardcoded', it can't be a variable. That doesn’t make sense to
> me either. In fact, once I fixed the part about empty strings being passed,
> and I figured out why I was getting no reverse match, Django was able to
> decipher the right parameter without me hardcoding it in the url tag, so I
> completely don’t understand what is going on there. If you’d care to
> enlighten me, please do.
>
> But I am not out of the woods yet. I posted a new request for help here:
> https://groups.google.com/forum/#!topic/django-users/fbiVWytyz5w
>
> . I invite you to share your wisdom.
>
Well, I must confess to being completely puzzled by what you're saying
here. Why would you need to hardcode the parameter? Why do you say it can't
be a variable? It can, of course: if you had a URL defined as
`(r'^color/(?P<color_name>\w+)/$, color_detail, name='color-detail')`, and
in your template context a list of strings ['red', 'blue', 'green'], then
you could produce a list of links via the URL tag by iterating:
{% for item in colors %}
<li>{% url "color_detail" color_name=item %}</li>
{% endfor %}
which will produce links pointing to /color/red/, /color/blue/, etc.
--
Daniel.
--
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 [email protected].
To post to this group, send email to [email protected].
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/f60839a1-248a-4f75-b433-faf9d4076010%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.