Python & Django

[Django] Django url tag( parameter )

응디 2021. 8. 25. 17:42

만약 html 에서 url을 통해 views로 parameter를 전달하고 싶다면? 

 

< index.html >

<!-- url로 type, cid param을 넘겨줌 -->
<a href="{% url 'test:test_send' type='sms' id=id %}">버튼</a>

< urls.py >

app_name = 'test'

path('test_send/<str:type>/<str:id>/', views.TestView.as_view(),
         name='test_send'),

< views.py >

class TestView(generic.View):
    def get(self, request, type, cid):
        # print로 잘 받아오는지 확인
		print(type, ' / ', cid)
        return type