I've installed django version 2.0 and default for urls is path I know that if in django 1.x can be urls and follow with regular expression, how do I use path for parameters instead of urls, and so I dont want to use urls because django by default add path not urls if its can be or use urls still I want to know how to use a path with parameters in django 2.0
here's my code
from django.urls import include, path
from . import views
urlpatterns = [
path('', views.articles_list),
path('add', views.articles_add),
path('edit', views.articles_edit)
]
Django URL pass parameter to view You can pass a URL parameter from the URL to a view using a path converter. Then “products” will be the URL endpoint. A path converter defines which type of data will a parameter store. You can compare path converters with data types.
The path function is contained with the django. urls module within the Django project code base. path is used for routing URLs to the appropriate view functions within a Django application using the URL dispatcher.
include() A function that takes a full Python import path to another URLconf module that should be “included” in this place.
Using regular expressions To do so, use re_path() instead of path() . In Python regular expressions, the syntax for named regular expression groups is (? P<name>pattern) , where name is the name of the group and pattern is some pattern to match.
path('edit/<int:id>', views.articles_edit)
you can add parameters like this
in view
def edit(request, id):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With