It's really problematic to generate all the URLs (there are a lot of
them) in the view and then retrieve the correct ones in the correct
places in the template.  It seems odd to me that {% url %} shouldn't
be able to take a variable view name.


On Nov 17, 7:24 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Tue, Nov 17, 2009 at 7:05 PM, ringemup <ringe...@gmail.com> wrote:
> > Is there any way to make the following work?  Right now it's throwing
> > a template syntax error, apparently treating "the_pattern" as a string
> > literal instead of a variable name and looking for a view named
> > "the_pattern".
>
> > [urls.py]
> > urlpatterns = patterns('',
> >    (r'^(?P<somevar>\s{1,8})/$', 'myapp.views.my_view', {}, 'my-view-
> > name'),
> > )
>
> > [views.py]
> > def my_view(request, somevar):
> >    return direct_to_template(request, 'template.html', extra_context=
> > {'the_pattern':'my-view-name', 'somevar':somevar})
>
> > [template.html]
> > <a href="{% url the_pattern somevar %}">some link text</a>
>
> Don't use {% url %} in the template but rather call reverse:
>
> http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse
>
> in the view and pass the result into the template.
>
> Karen

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.


Reply via email to