How do I add parameter in django 2.0 using path

Question:

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)
]
Asked By: Aslam H

||

Answers:

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

you can add parameters like this

in view

def articles_edit(request, id):
Answered By: Exprator

Application urls.py File Add Following code

path('blog/< int:blogid >', views.blog)

Application views.py file, add following code:

def blog(request, blogid):

Make sure both place name should be same (blogid)

Answered By: Sanket
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.