Routing urls.py By Convention

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# place this snippet in your app's views.py file.
# it assumes your app is called 'account', so change below as needed

import sys
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response
def route_request(request, path, urlparams):
  parameters = urlparams and urlparams[1:].split('/') or []
  funcname = 'process_request__%s' % path
  try:
    function = getattr(sys.modules[__name__], funcname)
  except AttributeError:
    return render_to_response('account/%s.dj' % path, { 'parameters': parameters })
  return function(request, parameters)

More like this

  1. Serve admin-media from urls.py by wolever 1 year, 9 months ago
  2. Database Routing by URL by dcwatson 3 years ago
  3. @url decorator - getting rid of urlpatterns by southern_sun 5 years, 9 months ago
  4. Copy media files to central location for easier sharing by jtiai 4 years, 1 month ago
  5. Serve static media and indexes from app directories [Python2.5, Development only] by adamlofts 4 years, 10 months ago

Comments

(Forgotten your password?)