Re: Pass variable as view name to {% url %}

2009-11-17 Thread ringemup

Thanks for the links.

On Nov 17, 7:56 pm, Karen Tracey  wrote:
> On Tue, Nov 17, 2009 at 7:33 PM, ringemup  wrote:
>
> > 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.
>
> Well, you're not alone, if you search the trac you will find:
>
> http://code.djangoproject.com/ticket/10980http://code.djangoproject.com/ticket/10745http://code.djangoproject.com/ticket/7917http://groups.google.com/group/django-developers/browse_thread/thread...
>
> But that's the way it is, so I gave you the solution I would use, since
> personally I prefer to do more in views and less in templates.  The
> discussion/tickets cited above might have other options noted that might
> appeal to you more.
>
> 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=.




Re: Pass variable as view name to {% url %}

2009-11-17 Thread Karen Tracey
On Tue, Nov 17, 2009 at 7:33 PM, ringemup  wrote:

>
> 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.
>
>
Well, you're not alone, if you search the trac you will find:

http://code.djangoproject.com/ticket/10980
http://code.djangoproject.com/ticket/10745
http://code.djangoproject.com/ticket/7917
http://groups.google.com/group/django-developers/browse_thread/thread/fd30cb20f80c6c79

But that's the way it is, so I gave you the solution I would use, since
personally I prefer to do more in views and less in templates.  The
discussion/tickets cited above might have other options noted that might
appeal to you more.

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=.




Re: Pass variable as view name to {% url %}

2009-11-17 Thread ringemup

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  wrote:
> On Tue, Nov 17, 2009 at 7:05 PM, ringemup  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\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]
> > some link text
>
> 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=.




Re: Pass variable as view name to {% url %}

2009-11-17 Thread Karen Tracey
On Tue, Nov 17, 2009 at 7:05 PM, ringemup  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\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]
> some link text
>

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=.