Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mjtamlyn/django-cbvpatterns
A nicer version of patterns() for use with class based views.
https://github.com/mjtamlyn/django-cbvpatterns
Last synced: 4 days ago
JSON representation
A nicer version of patterns() for use with class based views.
- Host: GitHub
- URL: https://github.com/mjtamlyn/django-cbvpatterns
- Owner: mjtamlyn
- License: bsd-2-clause
- Created: 2013-12-22T21:12:06.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2018-08-06T12:19:02.000Z (over 6 years ago)
- Last Synced: 2024-10-13T21:46:24.426Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 19
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Django-cbvpatterns
==================A nicer version of `patterns()` for use with class based views. Inspired
largely by Loic.What is this?
-------------If you're a big fan of class based views in Django, you might often find your
urls.py starting to look a little cluttered. Something like::from django.conf.urls import patterns, url
from ponies import views
urlpatterns = patterns('',
url(r'^$', views.Index.as_view(), name='index'),
url(r'^ponies/$', views.PonyList.as_view(), name='pony-list'),
url(r'^ponies/create/$', views.PonyCreate.as_view(), name='pony-create'),
url(r'^ponies/(?P\d+)/$', views.PonyDetail.as_view(), name='pony-detail'),
url(r'^ponies/(?P\d+)/edit/$', views.PonyUpdate.as_view(), name='pony-update'),
)The shortcuts you can use in patterns are really functional-view specific. The
functional version looks much nicer::from django.conf.urls import patterns, url
urlpatterns = patterns('ponies.views',
url(r'^$', 'index', name='index'),
url(r'^ponies/$', 'pony_list', name='pony-list'),
url(r'^ponies/create/$', 'pony_create', name='pony-create'),
url(r'^ponies/(?P\d+)/$', 'pony_detail', name='pony-detail'),
url(r'^ponies/(?P\d+)/edit/$', 'pony_update, name='pony-update'),
)So we can now have a class based view version which has the same feel::
from cbvpatterns import patterns, url
urlpatterns = patterns('ponies.views',
url(r'^$', 'Index', name='index'),
url(r'^ponies/$', 'PonyList', name='pony-list'),
url(r'^ponies/create/$', 'PonyCreate', name='pony-create'),
url(r'^ponies/(?P\d+)/$', 'PonyDetail', name='pony-detail'),
url(r'^ponies/(?P\d+)/edit/$', 'PonyUpdate, name='pony-update'),
)You can also pass in the actual view classes directly, rather than using the
string representation.Contributing
------------Development takes place
`on GitHub `_; pull requests are
welcome. Run tests with `tox `_.