Coder Social home page Coder Social logo

visgean / urljects Goto Github PK

View Code? Open in Web Editor NEW
55.0 7.0 7.0 102 KB

Deprecated! (Django routing without urls.py files, inspired by Flask.)

Home Page: https://urljects.readthedocs.org

License: BSD 3-Clause "New" or "Revised" License

Makefile 8.87% Python 91.13%
django extensions urls router

urljects's Introduction

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 Documentation Status Pypi Code Health Requirements Status Coverage Status

Library which greatly simplifies django urls definition! And as a side effect it makes translated urls amazingly easy. Just compare

# old urls notation
url('^detail/(?<slug>[\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.

    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.

from urljects import URLView, U, slug
from django.views.generic import DetailView

class ItemDetail(URLView, DetailView):
    name = 'detail'
    url = U / 'detail' / slug

A lot of people enjoy functional views, for those there is url_view decorator.

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(),

from urljects import U, slug, url

url_patterns = (
    url(U / 'detail' / slug, view=DetailView),
    # instead of
    url(r'^detail/(?P<slug>[\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.

urljects's People

Contributors

encukou avatar gitter-badger avatar katomaso avatar suor avatar visgean avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

urljects's Issues

implement url polymorfism

e.g.: multiple urls per class / function. It makes sense to implement this only for class based views.

urljects.views_include method

Something like this:

from urljects import url, view_include, I

url(I / 'eshop', view_include(eshop.views)),

This would enable to define urls in decorators and classes...

Cannot use U / ''

It's currently impossible to use the U / '' syntax:

>>> from urljects import U
>>> U / ''
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/miki/exp/pankow/lib/python3.4/site-packages/urljects/patterns.py", line 93, in __repr__
    return self.get_value() or ''
  File "/home/miki/exp/pankow/lib/python3.4/site-packages/urljects/patterns.py", line 68, in get_value
    if value[0] != beginning:
IndexError: string index out of range

I was wondering, is this really necessary? An alternative would be to allow just U.

i18n urls handling

Currently patterns translated using ugetext_lazy will cause exceptions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.