Opened 7 years ago

Closed 7 years ago

#9593 closed (invalid)

permalink breaks when using include() in

Reported by: IanLewis 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: UI/UX:


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 Changed 7 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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