讲解对象:NameError: name 'THEME' is not defined 作者:融水公子 rsgz 当我准备利用Django框架实现多主题切换的时候,出现了配置文件中NameError: name 'THEME' is not defined这样的错误。 配置文件是这样的: TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'themes', THEME, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]
目录结构是这样的:这里有两个主题 分别是默认主题 和bootstrap主题 分析:此次事件的主角就是THEME,说这个THEME没有定义,意思就是Django并不认识这个THEME,那怎么办呢?我们直接在setting里面定义一个THEME就能解决了 我们重新打开服务器,浏览器预览一下 果真成功了!!!
|