Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25907 closed New feature (wontfix)

Alternative Way of Specifying URL Patterns

Reported by: Sven R. Kunze Owned by: nobody
Component: Core (URLs) Version: dev
Severity: Normal Keywords:
Cc: tzanke@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Other frameworks (like MVC 5) provide an inline-way of specifying the URL pattern for a view.

Would it be possible to introduce such thing for Django?

Internally, we are working on something like this in order to accelerate development and maintenance for our production system.

Manually looking up URLs in the url.py and then jump to the actual view class is quite error-prone and tedious.

Internally, we evaluate two alternatives:

1) via class attribute: url
2) via decorator on class

# alternative 1
class ThingView(DetailView):
    url = '/thing(?P<pk>\d+)'
    template_name = 'thing.html'

# alternative 2
@url('/thing/(?P<pk>\d+)'):
class ThingView(DetailView):
    template_name = 'thing.html'

Change History (2)

comment:1 by Tim Graham, 9 years ago

Resolution: wontfix
Status: newclosed

You could propose it on the DevelopersMailingList (I couldn't find a past discussion from a quick seach), but I doubt we'd want to add another way of defining URLs. If you really want this in your own projects, you could possibly write an implantation that lives in each app's urls.py file and "autodiscovers" the URLs defined by your views according to whatever convention you want to use.

comment:2 by TZanke, 9 years ago

Cc: tzanke@… added
Note: See TracTickets for help on using tickets.
Back to Top