New Decorator Routing for Django

26 views
Skip to first unread message

Malik Brahimi

unread,
Aug 20, 2017, 5:07:52 PM8/20/17
to Django users
Hey guys! Do you mind checking out my new package and letting me know what you think? Essentially it is a Flask inspired routing system for Django (only Python2.x) that works by recursively searching through a folder, for example:

pip install djroute


urls.py 

from djroute import root, traverse 

urlpatterns
= [

   
# base pattern with admin routes

    url(r'^admin/', admin.site.urls),

]

# goes into folders relative to project root

views = root('app_name', 'views')


for i in traverse(views):

   
# add URLS to patterns

    urlpatterns.append(i)


djroute will recurse the entire tree defined with the root function by joining paths together


for example a subpackage might have a folder called banks with a folder inside called citizens with different modules one of which looks like so

from djroute import route

# @route(PATH:required, NAME:optional)

@route('fn', 'funcview')
def funcview(request):
   
# do something

@route('cls', 'classview')
class classview(View):

   
# do something in methods

This would generate the routes 

^banks/citizens/fn/$ with name funcview

^banks/citizens/cls/$ with name classview


if you like the packages to take a different name from their folder name, define PATH in __init__.py

Let me know if this does not make sense

Jani Tiainen

unread,
Aug 20, 2017, 11:56:55 PM8/20/17
to django...@googlegroups.com
Hi,

I just want to point out that there is similar work done for the core.


If we're lucky it will be available in Django 2.0.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c48d9b75-1b70-4bd1-bcf7-dbfde80eb1b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages