0

In the Django docs it says about url patterns:

It is possible to pass a string containing the path to a view rather than the actual Python function object. This alternative is supported for the time being, though is not recommended and will be removed in a future version of Django.

Does anyone have any insight as to why this the case? I find this alternative to be quite handy and can't find anything explaining why this is a bad (or, at least, less than ideal) idea.

1 Answer 1

3

I think the 1.8 Release Notes in the repo explains it quite well. Here's a summary of the main points:

In the modern era, we have updated the tutorial to instead recommend 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 using normal Python in place of "Django String Magic": the errors when you mistype a view name are less obscure, IDEs can help with autocompletion of view names, etc.

Thus patterns() serves little purpose and is a burden when teaching new users (answering the newbie's question "why do I need this empty string as the first argument to patterns()?"). For these reasons, we are deprecating it. Updating your code is as simple as ensuring that urlpatterns is a list of :func:django.conf.urls.url instances.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.