T
T
textmode2018-11-17 18:27:08
Django
textmode, 2018-11-17 18:27:08

How to pass two parameters to urls.py/views.py?

How to properly pass two url parameters to a view in Django 2?
Wrote like this:
urls.py:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
    path('sw/<str:t>/s<str:s>/', views.sinfo, name='sinfo'),
]

views.py:
def sinfo(request, t, s):
Opening address 127.0.0.1:8000/sw/t0830361/s1 and getting error:
sinfo() got an unexpected keyword argument 's'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
textmode, 2018-11-17
@textmode

I found my mistake, it is banal. In views there was another view with the same name. It was read after the view that I was picking and there was no s parameter in it.
Need to rest more often. :)

K
Konstantin Malyarov, 2018-11-17
@Konstantin18ko

some/url/<int:param1>/(^s[0-9]{4}$)/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question