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 GET parameter tag by marltu 1 year, 10 months ago
  2. Add site info to request context by bthomas 3 years, 6 months ago
  3. Load static media from secure (SSL) static server (Context Processor) by ianreardon 2 years, 7 months ago
  4. media_url context variable by marchino 5 years, 1 month ago
  5. Context processor for django admin app_list by alexander 2 years, 3 months ago

Comments

timo (on December 20, 2008):

Nice primer on how to integrate new template context processors.

#

(Forgotten your password?)