Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Visgean/urljects
Deprecated! (Django routing without urls.py files, inspired by Flask.)
https://github.com/Visgean/urljects
django extensions router urls
Last synced: 3 months ago
JSON representation
Deprecated! (Django routing without urls.py files, inspired by Flask.)
- Host: GitHub
- URL: https://github.com/Visgean/urljects
- Owner: Visgean
- License: bsd-3-clause
- Archived: true
- Created: 2015-07-05T20:38:08.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-06-28T09:10:45.000Z (over 5 years ago)
- Last Synced: 2024-07-24T03:25:17.982Z (3 months ago)
- Topics: django, extensions, router, urls
- Language: Python
- Homepage: https://urljects.readthedocs.org
- Size: 99.6 KB
- Stars: 55
- Watchers: 7
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- starred-awesome - urljects - Django routing without urls.py files, inspired by Flask. (Python)
README
# URLjects - project no longer maintained
Since Django 2.0 introduced new system of routing I dont think kind of approach is desired anymore.
[![Travis CL](https://img.shields.io/travis/Visgean/urljects.svg)](https://travis-ci.org/Visgean/urljects)
[![Documentation Status](https://readthedocs.org/projects/urljects/badge/?version=latest)](https://urljects.readthedocs.org/en/latest/)
[![Pypi](https://img.shields.io/pypi/v/urljects.svg)](https://pypi.python.org/pypi/urljects)
[![Code Health](https://landscape.io/github/Visgean/urljects/master/landscape.svg?style=flat)](https://landscape.io/github/Visgean/urljects/master)
[![Requirements Status](https://requires.io/github/Visgean/urljects/requirements.svg?branch=master)](https://requires.io/github/Visgean/urljects/requirements/?branch=master)
[![Coverage Status](https://coveralls.io/repos/Visgean/urljects/badge.svg?branch=master&service=github)](https://coveralls.io/github/Visgean/urljects?branch=master)Library which greatly simplifies django urls definition! And as a side effect it makes translated urls amazingly easy. Just compare
```python
# old urls notation
url('^detail/(?[\w-]+)', MyDetailView.as_view(), name='detail')
# easified !even translated! notation
url(U / _('detail') / slug, MyDetailView, name='detail')
```## Getting rid of ``urls.py``
With the use of ``include_view()`` you can avoid ``urls.py`` and include
your app's views directly in root ``urls.py``.```python
from urljects import view_include
# inside your root urls.py
urlpatterns = [
# old style
url("myapp/", include("myapp.urls")),
# new urljects style
url("myapp/", view_include("myapp.views"))
]
```#### Soo how to put urls directly into views?
I am glad you asked! For class based views simply inherit from ``URLView`` and add
``name`` and ``url`` as their attributes.```python
from urljects import URLView, U, slug
from django.views.generic import DetailViewclass ItemDetail(URLView, DetailView):
name = 'detail'
url = U / 'detail' / slug
```A lot of people enjoy functional views, for those there is ``url_view`` decorator.
```python
from urljects import url_view@url_view(U / 'category' / rest)
def detail(request, rest)
...
```After that you can user ``view_include`` instead of creating ``urls.py`` and
then old-style ``include`` them afterwards.## I want to keep my urls.py
Quite often you need some ``urls.py`` - for example your root urls. Then you can
use patterns like ``slug`` or ``rest`` as shown above inside your ``urls.py``.
We even provide modified ``url`` function to strip away the boilerplate of
``.as_view()``,```python
from urljects import U, slug, urlurl_patterns = (
url(U / 'detail' / slug, view=DetailView),
# instead of
url(r'^detail/(?P[\w-]+)' , view=DetailView.as_view(),
name='detail'),
)
```The name of the view has been taken from ``DetailView.url_name``.
There are also some common regular patterns like slugs and UUIDs so that you
can focus on more important stuff than on debugging regular expressions.