Opened 16 years ago

Closed 16 years ago

#9593 closed (invalid)

permalink breaks when using include() in

Reported by: Ian Lewis Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If you use include() to include urls in another then include will fail to generate the proper urls for urls in the included if the urls fall in a sub-path.

In the given

urlpatterns = patterns('',
    (r'', include('core.urls')),
    (r'^blog/(.*)', include('blog.urls')),


class Post(models.Model):
    """Post model."""
    title           = models.CharField(_('title'), max_length=200)
    slug            = models.SlugField(_('slug'), unique_for_date='publish')
    author          = models.ForeignKey(User, blank=True, null=True)
    body            = models.TextField(_('body'))
    publish         = models.DateTimeField(_('publish'))
    def __unicode__(self):
        return u'%s' % self.title

    def get_absolute_url(self):
        # return '/blog/%s/%s/%s/%s' % (self.publish.year,self.publish.strftime('%b').lower(),,self.slug)
        return ('blog_detail', None, {
            'year': self.publish.year,
            'month': self.publish.strftime('%b').lower(),
            'slug': self.slug

using the @permalink decorator will work for core.urls but it would not work for blog.urls. The permalink decorator simply returns an empty string.

Change History (1)

comment:1 by Malcolm Tredinnick, 16 years ago

Resolution: invalid
Status: newclosed

The only bug here is in the URL pattern you've created. You're capturing everything from blogs/ to the end of the string at the top level, so nothing will be seen by the second-level URLConf. Leave off the (.*) part and you'll find things work a lot better.

Note: See TracTickets for help on using tickets.
Back to Top