[Answered ]-Django autoroute

2๐Ÿ‘

โœ…

I think the reason django makes you write everything is something along these lines: What's wrong with "magic"?

Secondly, the map you are suggesting makes it difficult to deal with arguments to the view functions. The simplest would be to enforce by convention that all views only use GET and POST arguments and otherwise take some standard set of arguments (e.g. request, template_name).

To implement this map you want, you can iterate over your views module and generate the patterns object. Mind you, this is a really ugly hack and largely defeats the purpose of the url mapper. In urls.py:

from django.conf.urls.defaults import *

import myapp.views

urlpatterns = patterns('myapp.views',                                                                                                                                   
    *map(lambda x: url(r'^myapp/%s/$' % x, x, name='myapp_%s' % x),
         [k for k,v in myapp.views.__dict__.items() if callable(v)]))
๐Ÿ‘คrz.

Leave a comment