On Fri, Jun 5, 2009 at 8:17 AM, gnijholt <gijs.nijh...@gmail.com> wrote:

>
> I've used named URLs for some time now, never had any trouble with
> them.
> But now I have added an app 'website' to a new Django project.
> (version 1.1 beta 1 SVN-10924)
>
> My root urlconf (as defined in settings.py) contains an include to
> website.urls:
> ---
> urlpatterns = patterns('',
>    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
>    (r'^admin/', include(admin.site.urls)),
>    (r'^$', include('website.urls')),
> )
> ---
>

Notice you've specified the regex as r'^$' for the include of
'website.urls'.  So the only thing that is going to match is an empty
string.


>
>
> The included urlconf website.urls looks like this:
> ---
> from django.conf.urls.defaults import *
> from django.contrib.auth.decorators import login_required
> from django.views.generic.simple import direct_to_template
>
> urlpatterns = patterns('',
>    url(r'search/', 'website.views.search', name='website-search'),
>    url(r'^$', 'website.views.index', name='website-index'),
> )
> ---
>

Yet within it you have an entry for r'search/'.  This won't ever get used
since the only url that will get routed to website.urls is the empty string,
and that won't match r'search/'.  Thus you get:

The problem is that the {% url website-search %} tags don't work. They
> give this error:
> ---
> TemplateSyntaxError at /
> Caught an exception while rendering: Reverse for 'website-search' with
> arguments '()' and keyword arguments '{}' not found.
> ---
>

because there is no way construct a url that will get resolved to the
'website-search' named url as you have it set up.



>
> But if I move the 'search' entry to the root urlconf, it works..
> ---
> urlpatterns = patterns('',
>    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
>    (r'^admin/', include(admin.site.urls)),
>    url(r'search/', 'website.views.search', name='website-search'),
>    (r'^$', include('website.urls')),
> )
> ---


It works there because you've removed the constraint that in order to route
to 'website-search' the url must first match the empty string r'^$'.  So now
it is possible to reverse it.


>
> I'd rather have this entry in the included urlconf. This worked in the
> past..
> I don't understand why this won't work. What am I not seeing? Thanks
> for any help!
>

If you want 'website.urls' to handle anything not yet matched in the main
urls file, specify it as:

 (r'', include('website.urls')),

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-users@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=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to