Django 2.2之集成SimpleUI 3.8及KeyErrors: "simpletags"异常解决

#1. 环境

  • Windows 10
  • Python 3.6.1
  • VirtualENV
  • Django 2.2
  • SimpleUI 3.8
  • Eclipse 4.6.3 + PyDev 5.7
  • 内网环境
  • 官方上手指南

#2. Eclipse新建Pydev Django Project

F:\ECLIPSE463\SIMPLEUIOFFICETEST
│  .project
│  .pydevproject
│  db.sqlite3
│  manage.py
│
└─SimpleUIOfficeTest
    │  settings.py
    │  urls.py
    │  wsgi.py
    │  __init__.py
    │
    └─__pycache__
            settings.cpython-36.pyc
            urls.cpython-36.pyc
            wsgi.cpython-36.pyc
            __init__.cpython-36.pyc

#3. 设置项目的settings.py文件加入以下2句:

INSTALLED_APPS = [
    'simpleui',
	..........
]
SIMPLEUI_STATIC_OFFLINE = True  #能联网的可忽略

#4. 创建默认数据库文件

(django22) F:\eclipse463\SimpleUIOfficeTest>python manage.py makemigrations
No changes detected

(django22) F:\eclipse463\SimpleUIOfficeTest>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK

#5. 创建超级管理员

(django22) F:\eclipse463\SimpleUIOfficeTest>python manage.py createsuperuser
Username (leave blank to use 'admin'): admin
Email address: [email protected]
Password:
Password (again):
Superuser created successfully.

#6. 启动项目并查看

python manage.py runserver
#浏览器打开
http://127.0.0.1:8000/admin/

#7. 异常提示

KeyErrors: "simpletags"

#8. 原因及解决

报错来源: 是simpleui安装路径下\site-packages\simpleui\templates\admin的login.html引入{% load i18n static simpletags %}, 但是找不到simpletags所致。
原因:是安装simpleui时, 不知何故源码包里明明存在templatetags文件夹, 但是安装完成后不见了。
解决:直接把源码包里的templatetags文件夹拷贝到\site-packages\simpleui\下面即可。
simpleui
├─static
│  ├─admin
│  └─import_export
├─templates
│  ├─admin
│  └─registration
└─templatetags
   └─simpletags.py

你可能感兴趣的:(Django)