How To Put A Page Under Active Menu Item with Django Sitetree

Oct 09, 2013 · Updated: Jul 12, 2021 · by Tim Kamanin

Django sitetree is a great app to manage your Django app menus. Sometimes, you'll have a page that you want to manually put under a sitetree, so how to do that? At first we need to patch a like this:

@@ -288,6 +288,9 @@
 # urlquote is an attempt to support non-ascii in url.
 current_url = urlquote(self._global_context['request'].path)
+if self._global_context.get('sitetree_current_url'):
+  current_url = self._global_context.get('sitetree_current_url')
 urls_cache = self.get_cache_entry('urls', tree_alias)
 if urls_cache:
   for url_item in urls_cache:

After that, you can set any menu item as active by just specifying its url in your context, for example:

context["sitetree_current_url"] = "/some-url-path-that-you-want-to-set-as-an-active/"

Hey, if you've found this useful, please share the post to help other folks find it:

There's even more:

Subscribe for updates

  • via Twitter: @timonweb
  • old school RSS:
  • or evergreen email ↓ ↓ ↓