Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "path" mean in Django urls

Tags:

python

django

When a read some new project on Django in one of urls.py files i find following code:

from django.urls import path
from . import views

urlpatterns = [
    path('buyers/embed/<int:id>/view', views.buyers_view),
]

This is written in application that not used for now (Instead of this is used another application for buyers view). But i want to know what is this path.

I can't find any information about it in documentation. Maybe this is some old style for url routing, or some mistakes.

Thanks for any help.

like image 924
Vladyslav Avatar asked Sep 26 '17 16:09

Vladyslav


People also ask

What is difference between path and URL in Django?

In Django 2.0, you use the path() method with path converters to capture URL parameters. path() always matches the complete path, so path('account/login/') is equivalent to url('^account/login/$') . The part in angle brackets ( <int:post_id> ) captures a URL parameter that is passed to a view.

What does name in path do in Django?

By defining a name in a path, we thus first need to define such identifier, and we can define a name for such path. Django will then do the math, and replace it with the correct URL. Not only does this save us a headache, the URL is also guaranteed to be correct (given of course the name itself is correct).

What is the difference between path and re_path in Django?

For my understanding is that the path function does not accept regex urls anymore, you need to use the new urls syntax <slug:title> instead of passing a regex to match parameters. The re_path only work with regex formatted urls (The old way we make urls).

What is path converter Django?

Path convertersint - Matches zero or any positive integer. Returns an int . slug - Matches any slug string consisting of ASCII letters or numbers, plus the hyphen and underscore characters. For example, building-your-1st-django-site .


1 Answers

path() is from the new URL syntax, which was added in Django 2.0.

You can find out more information in the tutorial or url docs, as long as you have Django 2.0 or later selected on the documentation site.

like image 50
Alasdair Avatar answered Sep 27 '22 02:09

Alasdair