djano is not a registered tag 中间件注册问题
djano is not a registered tag 中间件注册问题
Django自定义simple_tag时出错如下:
解决办法:
在settings里的 加上红色的部分,my_tag为自定义的标签函数 后面的为其地址
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, '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',
],
'libraries':{
"my_tag":"app02.templates.my_tag",
},
},
},
]
# tid = self.request.POST.get['tempid'] [错误导不玫
tid = self.request.POST.get('tempid')
tid = self.request.POST.get['tempid']
TypeError: 'method' object is not subscriptable
AH01909: www.example.com:443:0 server certificate does NOT include an ID....
File "d:\\python37\\lib\\site-packages\\django\\db\\backends\\mysql\\base.py", line 36, in <module>\r
[Sat Nov 09 16:11:58.331000 2019] [wsgi:error] [pid 20144:tid 976] [client 127.0.0.1:57521] raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)\r
[Sat Nov 09 16:11:58.331000 2019] [wsgi:error] [pid 20144:tid 976] [client 127.0.0.1:57521] django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.\r
#if version < (1, 3, 13):
# raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
Traceback (most recent call last):\r
[Sat Nov 09 16:03:51.575000 2019] [wsgi:error] [pid 4788:tid 936] [client 127.0.0.1:57113] File "d:\\python37\\lib\\site-packages\\django\\db\\backends\\mysql\\base.py", line 15, in <module>\r
[Sat Nov 09 16:03:51.575000 2019] [wsgi:error] [pid 4788:tid 936] [client 127.0.0.1:57113] import MySQLdb as Database\r
[Sat Nov 09 16:03:51.575000 2019] [wsgi:error] [pid 4788:tid 936] [client 127.0.0.1:57113] ModuleNotFoundError: No module named 'MySQLdb'\r
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.\r
[Sat Nov 09 16:03:51.575000 2019] [wsgi:error] [pid 4788:tid 936] [client 127.0.0.1:57113] Did you install mysqlclient?\r
问题如下:
解决方法:
我的python是3.7版本,所以在命令行安装支持python3以上的驱动(如果django配置的虚拟环境,请先进入虚拟环境)
pip install pyMySQL
1
接着在django的__init__.py输入并保存
import pymysql
pymysql.install_as_MySQLdb()
1
2
最后验证下,没有再报错。
各类模块要安装在python 目录 下,可能是我设的没在虚拟环境下进行