记录将微信公众号验证文件放在网站域名或项目根目录下的问题
需求
问题出错代码:
Internal Server Error: /MP_verify_PO****************.txt
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 202, in _get_response
response = response.render()
File "/usr/local/lib/python3.7/site-packages/django/template/response.py", line 105, in render
self.content = self.rendered_content
File "/usr/local/lib/python3.7/site-packages/django/template/response.py", line 81, in rendered_content
template = self.resolve_template(self.template_name)
File "/usr/local/lib/python3.7/site-packages/django/template/response.py", line 63, in resolve_template
return select_template(template, using=self.using)
File "/usr/local/lib/python3.7/site-packages/django/template/loader.py", line 47, in select_template
raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: MP_verify_PO*********************.txt
原因:找不到目标文件
解决方式: django框架下的setting.py 设置template有一项嘶 dirs 设置为 'DIRS': [os.path.join(BASE_DIR, 'templates')], 如下图
然后修改ulrs.py文件
path('MP_verify_POapobxMaPqYGBGt.txt', TemplateView.as_view(template_name='MP_verify_POapobxMaPqYGBGt.txt', content_type='text/plain')),
一般这样就可以 如果不可以的话 将templates文件夹移到与app同级路径下 再将目标文件放在templates下
解决