Abhay Raghuvanshi
Abhay Raghuvanshi

Reputation: 131

difference between URL and path in Django?

I just started learning Django, and not able to understand that what is the actual difference between URL and path in Django.

Upvotes: 6

Views: 8934

Answers (3)

DaveB
DaveB

Reputation: 472

I know that this is an older question, but to answer the question directly:

  • Since Django 2.0, the url() function is an alias to django.urls.re_path()
  • And, it is listed as deprecated since Django 3.1.

So, you should use either path() or re_path() moving forward, depending on which meets your needs.

Upvotes: 6

Bhavani Ravi
Bhavani Ravi

Reputation: 2291

Until Django 1.11 there was nothing called a path to define app urls. Django 2.0 introduces path as a replacement for URL. Since you have just started with Django stick with 2.0 documentation and keep in mind that every forum you check will have solutions for older versions of Django

Upvotes: 13

Tyson
Tyson

Reputation: 424

HTTP URLs are defined in section 3.3 of RFC 1738:

An HTTP URL takes the form:

http://<host>:<port>/<path>?<searchpart>

Given a URL such as https://www.djangoproject.com/download/, the path is just /download/.

Sadly, Django often confuses paths and URLS. For example, all of the code examples for the get_absolute_url() method in the documentation return paths, not URLs.

Some parts of Django do get it right though, such as request.path and request.build_absolute_uri() which use the correct terms.

Upvotes: 1

Related Questions