title: How to recursively get absolute url from parent instance(s)?
body: <p>I have a page model that contains instance of itself as possible parent page. So every page can be child of another page. What I would like to do is get the absolute url to give me link that is structured according to its parent architecture. So let's say I have a Page AAA with child BBB, which itself has a child CCC. The url of last child would be mysite.com/AAA/BBB/CCC. I've played around and figured a recursive method that would work for me, however I hit a brick wall on resolving the urls.</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class Page {
       ...
       parent = models.ForeignKey('self', null=True, blank=True, unique=False)
       ....
  
       def get_parent_path(self, list=None):
  
            parenturl = []
  
            if list is not None:
                parenturl = list
  
            if self.parent is not None:
                parenturl.insert(0,self.parent.slug)
                return self.parent.get_parent_path(parenturl)
  
            return parenturl
  
       def get_absolute_url(self):
  
            path = ''
  
            if self.parent is not None:
                 parentlisting = self.get_parent_path()
                 for parent in parentlisting:
                      path = path + parent + '/'
  
            path = path + self.slug;
  
            return reverse("pages:details", kwargs={"path": path, "slug": self.slug})
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>     url(r'^(?P&lt;path&gt;.+)(?P&lt;slug&gt;[\w-]+)/$', views.page, name='details'),
  </code></pre>
  
  <p>Testing it, showed me that path I get gives the correct parental part of the path. But resolving urls doesn't seem to work and I'm thinking it has something to do with reverse and/or regex. Using any page link, even where 404 should be, will now give me type error.</p>
  
  <pre><code>TypeError at /###/###/
  
  page() got an unexpected keyword argument 'path'
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>EDIT:</p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>def page(request, slug):
  
      instance = get_object_or_404(Page, slug=slug)
  
      context = {
          "title": instance.title,
          "page": instance,
      }
  
      return render(request, "page.html", context)
  </code></pre>