Django1.11 CBV获取指定url参数

url传参

from django.conf.urls import url
from demo import views
urlpatterns = [
	url(r'/(?P[0-9]{4})', views.DemoView.as_view(), name='demo')
]

捕获参数

from django.views.generic import View
from django.http import HttpResponse

class DemoView(View):
	def get(self, request, year):
		return HttpResponse(year)
	
	# 也可以用**kwargs获取
	def get(self, request, **kwargs):
		return HttpResponse(kwargs.get('year'))

大家有问题可以微信交流一下~~

你可能感兴趣的:(python,django)