On 26 Aug., 17:08, bruno desthuilliers <bruno.desthuilli...@gmail.com> wrote: > > So would it be possible to access the request.path property from > > within a custom template tag? > > Of course, as long as > 1/ you pass it explicitely or > 2/ the request.path is available in the context passed to the tag's > render() method. > > You may want to have a look at context_processors and ContextRequest > in the fine manual.
Hello Bruno, thanks for your answer. I'm already using a custom context_processor (yay! ;-), so I'll follow that suggestion, too. I've tried wrapping my head around the process_view function, but I'm not exactly clear on how it works just yet. So juet for laffs, I wrote my first custom template tag (another yay! ;-) and it does the job nicely: ##### snip snip from django import template import re area_pattern=re.compile(r"/(?P<country_code>[a-z]{2})/(?P<area_code>[a- z]{2,3})/") country_pattern=re.compile(r"/(?P<country_code>[a-z]{2})/") register = template.Library() def pathfinder(request): result = area_pattern.match(request.path) if result: return result.group()[:-1] result = country_pattern.match(request.path) if result: return result.group()[:-1] return "" register.simple_tag(pathfinder) ### snip snip so now in my navigation bar (actually it's just a table <td>), I can employ the following syntax: <a href="{% pathfinder request %}{% url club300.views.observation_add %}">add observation</a><br> and the URL will change according to the path via which I'm accessing the view. It's probably not a good idea to have google groups archive this ugly hack with my name on it, but right now it seems to do the job nicely. Storing the data in the request object also seems like a great idea, I'll certainly look into that! Of course you're right about having to change two spots in case I ever decide to redesign my URL's, so a refactoring is in order! All the best, Uwe -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.