Opened 16 years ago
Closed 16 years ago
#9593 closed (invalid)
permalink breaks when using include() in urls.py
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 |
Description
If you use include()
to include urls in another urls.py then include will fail to generate the proper urls for urls in the included urls.py if the urls fall in a sub-path.
In the given urls.py
... urlpatterns = patterns('', (r'', include('core.urls')), (r'^blog/(.*)', include('blog.urls')), ) ...
and models.py
... 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 @permalink def get_absolute_url(self): # return '/blog/%s/%s/%s/%s' % (self.publish.year,self.publish.strftime('%b').lower(),self.publish.day,self.slug) return ('blog_detail', None, { 'year': self.publish.year, 'month': self.publish.strftime('%b').lower(), 'day': self.publish.day, '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.
Note:
See TracTickets
for help on using tickets.
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.