Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add parameter in django 2.0 using path

Tags:

python

django

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)
]
like image 802
Aslam H Avatar asked Dec 20 '17 07:12

Aslam H


People also ask

How do I pass parameters via URL in Django?

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.

Is URL and path same in Django?

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.

What is path include in Django?

include() A function that takes a full Python import path to another URLconf module that should be “included” in this place.

Which method is used instead of path in Django?

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.


1 Answers

path('edit/<int:id>', views.articles_edit)

you can add parameters like this

in view

def edit(request, id):
like image 65
Exprator Avatar answered Sep 22 '22 05:09

Exprator