问题描述及解决方案:
在使用Django进行管理端开发时,默认使用django自带的admin app,但是业界用的比较多的是xadmin,至于它的优势,作者已经写得很清楚了:
- Drop-in replacement of Django admin
- Twitter Bootstrap based UI with theme support
- Extensible with plugin support
- Better filter, date range, number range, etc.
- Built-in data export with xls, csv, xml and json format
- Dashboard page with widget support
- In-site bookmarking
- Full CRUD methods
其实有一点不好的地方就是安装不太方便,往往在使用的时候要根据实际出现的错误需要改源码;)
我在安装的时候就遇到了两个问题:
- SyntaxWarning: “is” with a literal. Did you mean “==”?
‘selected’: (self.lookup_exact_val is ‘’ and self.lookup_isnull_val is ‘’),
这个其实问题不大就是把is 改成 == 就好了。因为从python 3.8时会报语法错误。 - ImportError: cannot import name ‘SKIP_ADMIN_LOG’ from ‘import_export.admin’
这个问题比较棘手,实际上因为文件lib\site-packages\xadmin\plugins\importexport.py 导入SKIP_ADMIN_LOG的时候没有找到。代码修改如下:
#from import_export.admin import DEFAULT_FORMATS, SKIP_ADMIN_LOG, TMP_STORAGE_CLASS
from import_export.admin import DEFAULT_FORMATS, ImportMixin, ImportExportMixinBase
def get_skip_admin_log(self):
if self.skip_admin_log is None:
#return SKIP_ADMIN_LOG
return ImportMixin(ImportExportMixinBase).get_skip_admin_log()
else:
return self.skip_admin_log
def get_tmp_storage_class(self):
if self.tmp_storage_class is None:
#return TMP_STORAGE_CLASS
return ImportMixin(ImportExportMixinBase).get_tmp_storage_class()
参考博文:https://blog.csdn.net/weixin_40459875/article/details/112412145