> -----Original Message----- > From: django-users@googlegroups.com > [mailto:[EMAIL PROTECTED] On Behalf Of V > Sent: 11 July 2008 09:31 > To: Django users > Subject: Re: how does {% url %} work? > > > > > but it gives only > > > /projects/join/6/ > > > > That's exactly what's expected. > > Have you ever checked the docs (http://www.djangoproject.com/ > documentation/templates/#url)? This /clients/client/123/ is expected! > > if I do > (r'^coosci/$', include('coosci.webapp.urls')), it won't work > as $ closes the regex, so this is where the url should end, I > think this is simply wrong (I even tried it, and it was wrong) > > I tried to replicate the setting in the docs at > http://www.djangoproject.com/documentation/templates/#url > 0. cd to my_project dir > 1. python manage.py startapp app_name > 2. add the urls.py snippet ('^clients/', > include('my_project.app_name.urls')) to the main urls.py 3. > create a new urls.py under app_name, and add to it > ('^client/(\d+)/ $', 'app_views.client') 4. create > app_views.py and define a view that simply shows the url with > {% url app_views.client client.id %} > > then at http://127.0.0.1:8000/clients/client/1 I get a > ViewDoesNotExist error, for some reason the app_view.py file > isn't treated as a module, and it can't be imported. > There is an __init__.py in the directory as created by startapp. > > I think what happens is that in django/core/urlsresolvers.py > get_callable finds properly the mod_name=app_name and > func_name=client, but its import statement (line 47) fails as > app_name in itself can't be seen from the project_root for example. > > I was playing with it a bit, and what worked is the following: > 3. create a new urls.py under app_name, and add to it > ('^client/(\d+)/ $', 'app_name.app_views.client') 4. create > app_views.py and define a view that simply shows the url with > {% url app_name.app_views.client client.id %} > > I hope this will help someone as well! > > In the meantime I just realised that my problem was another > row in the main urls.py: > #(r'^$', include('coosci.main_app.urls')), --> this was the > problem, so django docs was indeed correct except for the {% > url %} syntax > ('^clients/', include('project_name.app_name.urls')) > > Cheers, V
That is what I meant when I said ('^clients/$', include('project_name.app_name.urls')) - I just forgot to take out the $!! Sorry! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---