urlpatterns = [path(".html", TestView.as_view(), {"name": [3, 4, 5, "dsadadsad"]}, name="test"),] # 定制可选变量,可选变量必须为dict,且必须在视图函数之后
用法:
class TestView(View):
TEMPLATE = "test.html"
def get(self, request, *args, **kwargs):
name = kwargs.get('name') # 路由定义之可选变量,如此获得
return render(request, self.TEMPLATE)