我正在尝试将 django-simple-history 插件与 django 1.10 版一起使用
根据文档:
使用以下命令安装插件:
pip install django-simple-history
将 simple_history 添加到 INSTALLED_APPS
INSTALLED_APPS = [ ... 'simple_history', ]
要跟踪模型的历史记录,请在模型上创建一个 simple_history.models.HistoricalRecords 实例:
class ModelClass(models.Model): name1 = models.CharField(max_length=300) name2 = models.CharField(max_length=300) name3 = models.CharField(max_length=300) history = HistoricalRecords(table_name='sampls_modelclass_history') class Meta: db_table = "sample_modelclass"
为了允许在 Django 管理站点上查看以前的模型版本,在向管理站点注册模型时继承自 simple_history.admin.SimpleHistoryAdmin 类:
from django.contrib import admin from simple_history.admin import SimpleHistoryAdmin from .models import ModelClass admin.site.register(ModelClass, SimpleHistoryAdmin)
当我尝试在管理员中的特定 ModelClass 实例上输入“历史记录”时,出现以下异常:
TypeError: render() got an unexpected keyword argument 'dictionary'
追溯:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/org/modelclass/1/history/
Django Version: 1.10
Python Version: 2.7.11
Installed Applications:
['etc',
'org',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'simple_history']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
**Traceback:**
File "C:\Python27\lib\site-packages\django\core\handlers\exception.py" in inner
39. response = get_response(request)
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\options.py" in wrapper
544. return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in inner
211. return view(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\simple_history\admin.py" in history_view
79. dictionary=context, current_app=request.current_app)
Exception Type: TypeError at /admin/org/modelclass/1/history/
Exception Value: render() got an unexpected keyword argument 'dictionary'
请指教解决方法!