以前曾经用过media这种全局变量
现在我们自定义全局语境:context
(不知道谁翻译的叫上下文,感觉没翻译好)
简易版
在app目录下自己建一个context
名字是my_context_processors.py
def getData(request):
return {
'uname': 'zhangsan'}
在setting里,先把之前的media过滤掉,否则会报错
‘django.template.context_processors.media’
注册刚才的context
'stu.my_context_processors.getData'
写url、view和html
path('index7/', views.Index7View.as_view()),
class Index7View(View):
def get(self, request):
return render(request, 'index7.html')
{
{
uname }