Add URL Segments to Templates

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def url_segments(request):

	from urlparse import urlparse
	
	# convert the url path into a list	
	url_segment = request.path_info.strip("/").split("/")
	
	# assign each segment to it's on var
	url_segment_dict = {}
	for i in range(len(url_segment)):
		url_segment_dict["segment_%d" % (i+1)] = url_segment[i]
	
	return url_segment_dict

More like this

  1. Add site info to request context by bthomas 4 years, 6 months ago
  2. Template context processor to make the settings.py values available in templates by tamizhgeek 2 years ago
  3. media_url context variable by marchino 6 years, 1 month ago
  4. Google Analytics Template Tag by jarofgreen 3 years, 9 months ago
  5. Private Context Decorator by acdha 3 years, 9 months ago

Comments

timo (on December 20, 2008):

Nice primer on how to integrate new template context processors.

#

(Forgotten your password?)