{% url in templates

2 views
Skip to first unread message

Umapathy S

unread,
Oct 28, 2009, 2:55:22 PM10/28/09
to django...@googlegroups.com
Hello there,

I am developing a page which has a left side menu.  This menu is a seperate html and gets includes in the base.html template.

To make it less vulnerable to url changes, I am trying to implement the {% url %}

in lhsmenu.html

<div class="LHSMenu">
<ul class="menu expandfirst" id="menu1">
    <li><a href="#">view</a>
    <ul>
        {% url exps.view_xyz as viewxyzurl %}
        <li><a href="{{ viewxyzurl }}">xyz</a></li>
    </ul></li>
</ul>
</div>

I tried

        <li><a href="{% url exps.view_xyz %}">xyz</a></li>


Exception Type: TemplateSyntaxError
Exception Value:
Caught an exception while rendering: Reverse for 'exps.view_xyz' with arguments '()' and keyword arguments '{}' not found.


What could be the issue.  Any help much appreciated.

Thanks


David Zhou

unread,
Oct 28, 2009, 2:59:57 PM10/28/09
to django...@googlegroups.com
What's your 'view_xyz'?  

Are you sure that view_xyz is accessible through an URL without any arguments?

-- dz

Gabriel .

unread,
Oct 28, 2009, 3:05:31 PM10/28/09
to django...@googlegroups.com

Is your view called exps.view_xyz or view_xyz? Would be usefull if you
paste your urls.py conf.

--
Kind Regards

Umapathy S

unread,
Oct 28, 2009, 3:16:46 PM10/28/09
to django...@googlegroups.com
view_xyz is the view function.  No arguments.

exps is the application.  pams is project.

pams/urls.py

urlpatterns = patterns('',
    # Example:
    # (r'^pams/', include('pams.foo.urls')),
    (r'pams/', include('pams.exps.urls')),


pams/exps.urls.py

from django.conf.urls.defaults import *
from django.views.generic import list_detail
from pams.exps.models import *

urlpatterns = patterns('pams.exps.views',
    (r'exps/xyz/$', 'view_xyz'),

 
view_xyz is defined in pams/exps/views.py.  Its just a dummy function which gets some data through POST and prints out a table.

Thanks

Umapathy

Gabriel .

unread,
Oct 28, 2009, 4:03:11 PM10/28/09
to django...@googlegroups.com
On Wed, Oct 28, 2009 at 4:16 PM, Umapathy S <nsup...@gmail.com> wrote:
> view_xyz is the view function.  No arguments.
>
> exps is the application.  pams is project.
>
> pams/urls.py
>
> urlpatterns = patterns('',
>     # Example:
>     # (r'^pams/', include('pams.foo.urls')),
>     (r'pams/', include('pams.exps.urls')),
>
>
> pams/exps.urls.py
>
> from django.conf.urls.defaults import *
> from django.views.generic import list_detail
> from pams.exps.models import *
>
> urlpatterns = patterns('pams.exps.views',
>     (r'exps/xyz/$', 'view_xyz'),
>

Try with {% url exps.views.view_xyz ....

or "pams.exps.views.view_xyz"

{%

--
Kind Regards

Umapathy S

unread,
Oct 28, 2009, 4:29:13 PM10/28/09
to django...@googlegroups.com

Thanks. 

 {% url exps.views.view_xyz %} worked. 

Is it possible to do this for generic views? 


Thanks

Umapathy

Alex Robbins

unread,
Oct 29, 2009, 9:40:02 AM10/29/09
to Django users
Maybe it is just me, but I feel like writing out the view functions
like that is a beating. I just name[1] all the urls. Then the url tag
is easy. I just do things like {% url home-page %} or {% url blog-
index %}. If you set up a generic view in the views and name it, it
will work like normal.

[1]http://docs.djangoproject.com/en/dev/topics/http/urls/#id2

On Oct 28, 3:29 pm, Umapathy S <nsupa...@gmail.com> wrote:
> On Wed, Oct 28, 2009 at 8:03 PM, Gabriel . <gabriel....@gmail.com> wrote:

bruno desthuilliers

unread,
Oct 29, 2009, 12:45:16 PM10/29/09
to Django users

On 29 oct, 14:40, Alex Robbins <alexander.j.robb...@gmail.com> wrote:
> Maybe it is just me, but I feel like writing out the view functions
> like that is a beating.

It's not just you !-)

yeps, named urls are the RightThing(tm) to do.

Umapathy S

unread,
Oct 29, 2009, 1:37:42 PM10/29/09
to django...@googlegroups.com
On Thu, Oct 29, 2009 at 1:40 PM, Alex Robbins <alexander...@gmail.com> wrote:

Maybe it is just me, but I feel like writing out the view functions
like that is a beating. I just name[1] all the urls. Then the url tag
is easy. I just do things like {% url home-page %} or {% url blog-
index %}. If you set up a generic view in the views and name it, it
will work like normal.

[1]http://docs.djangoproject.com/en/dev/topics/http/urls/#id2

bingo... believe me I searched through the docs, but never got to url dispatcher.  proves i am a django newbie !!!

Thanks a ton.

-Umapathy
Reply all
Reply to author
Forward
0 new messages