I'm thinking more and more that a nice, simple Django improvement
would be to allow URLconfs to specify the view object itself, rather
than a string representing the path to the view.
Old example:
urlpatterns = patterns('',
(r'^map/$', 'mysite.views.the_map'),
)
New example:
from mysite.views import the_map
urlpatterns = patterns('',
(r'^map/$', the_map),
)
This would help make Django apps more portable, because a URLconf
could do a relative import to get the views. Example:
from views import the_map # relative import
urlpatterns = patterns('',
(r'^map/$', the_map),
)
The only downside to this would be the repetition of having to import
the views first before passing them to the URLconf, but I guess you
could do a "from views import *" if you were really lazy. You could
also put the views inside your URLconf, like so:
def my_view(request):
return HttpResponse('Hello world')
urlpatterns = patterns('',
(r'^hello/$', my_view),
)
Note that putting views inside the URLconf is already possible via
something like this (which is a bit ugly but works):
def my_view(request):
return HttpResponse('Hello world')
urlpatterns = patterns('',
(r'^hello/$', __module__ + 'my_view'),
)
Thoughts?
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---