airnet
airnet

Reputation: 2673

django - "urls" function sometime included in urls.py

Why is it in some urls.py files you see url(..) and in others you see (..).

For example

urlpatterns = patterns('',
    url('hello','article.view.hello')
)

and in others i see :

urlpatterns = patterns('',
    ('article/', include('article.urls'))
)

Upvotes: 0

Views: 63

Answers (2)

Kevin Christopher Henry
Kevin Christopher Henry

Reputation: 49012

The use of patterns() makes the use of url() optional. Going forward, however, patterns will be deprecated and you will have to always use url. See this ticket:

The other thing that patterns provides besides the prefix parameter is automatically wrapping plain tuples in urlpatterns in url(). I think removing this and forcing usage of url() will be a good cleanup.

So you should get in the habit of always using url.

Upvotes: 1

lehins
lehins

Reputation: 9767

Thank you for clarification with your edit:

  • First one points to the view
  • second one allows you to add another patterns list from separate module (or from the same one)

But usage of url is purely for convenience (but will be required in django 2.0). You can see the check here:

https://github.com/django/django/blob/master/django/conf/urls/init.py#L55

Upvotes: 0

Related Questions