﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22218	Deprecate 'prefix' arg to django.conf.urls.patterns	Carl Meyer	Tim Graham	"In the olden days of Django, it was encouraged to reference views as strings in url patterns:

{{{
urlpatterns = patterns('',
    url('^$', 'myapp.views.myview'),
)
}}}

and Django would magically import ""myapp.views.myview"" internally and turn the string into a real function reference.

In order to reduce repetition when referencing many views from the same module, the `patterns` function takes a required initial ""prefix"" arg, which is prepended to all views-as-strings in that set of url patterns:

{{{
urlpatterns = patterns('myapp.views',
    url('^$', 'myview'),
    url('^other/$', 'otherview'),
)
}}}

In the modern era, we have updated the tutorial to instead recommend actually importing your views module and referencing your view functions (or classes) directly. This has a number of advantages, all deriving from the fact that we are now using Normal Python in place of Django String Magic: the errors when you mistype a view name are less obscure, IDEs can help with autocompleting view names, etc.

With the advent of the class-based generic views, it is even more likely that users are referencing view callables directly in their urlconf, due to the need to call `.as_view()`.

So these days, the above use of the prefix arg is much more likely to be written (and is better written) as:

{{{
from myapp import views

urlpatterns = patterns('',
    url('^$', views.myview),
    url('^other/$', views.otherview),
)
}}}

This leaves the 'prefix' arg in modern Django code as a useless empty string that has to be passed to every invocation of `patterns`. This is an ugly API wart, and a burden when teaching new users (answering the newbie's question ""why do I need this empty string as the first argument to patterns?"" requires either a time-wasting detour into the history of Django URLconfs or a hand-wavy ""don't worry, just do it"").

I suggest that we deprecate this argument. This will require type-checking the first argument to `patterns` for the duration of the deprecation period, but I don't think that's so bad.

(I would not be opposed to deprecating the entire views-as-strings feature, but the additional gain there is only code we can remove and stop maintaining, not a benefit to the public API, so I decided to keep this proposal minimal. If there's consensus to deprecate the entire feature, I will happily update the summary to reflect that.)"	Cleanup/optimization	closed	Core (URLs)	dev	Normal	fixed		loic@… Simon Charette	Accepted	1	0	0	0	0	0
