服务器部署Django启动报错,UEditor问题处理

以下问题是,出现在Ubuntu18下安装Django UEditor 出现的

ModuleNotFoundError: No module named 'widgets'

这种问题处理方法:

下载最新版本的DjangoUed3,在github下载兼容python3的DjangoUeditor,将DjangoUeditor放入到自己运行的虚拟坏境中

接着又会报如下的错误:

ImportError: No module named 'settings'

这是因为,在python 环境中DjangoUeditor 下的widgets.py 导入中, 

import settings as USettings

 这里的导入需要修改为

from . import settings as USettings

这个问题即可解决

紧接着还有下个问题

AttributeError: 'dict' object has no attribute 'has_key'

File "/root/.virtualenvs/abc_block_chain/lib/python3.6/site-packages/DjangoUeditor/models.py", line 4, in <module>
    from .widgets import UEditorWidget, AdminUEditorWidget
  File "/root/.virtualenvs/abc_block_chain/lib/python3.6/site-packages/DjangoUeditor/widgets.py", line 8, in <module>
    from . import settings as USettings
  File "/root/.virtualenvs/abc_block_chain/lib/python3.6/site-packages/DjangoUeditor/settings.py", line 101, in <module>
    UpdateUserSettings()
  File "/root/.virtualenvs/abc_block_chain/lib/python3.6/site-packages/DjangoUeditor/settings.py", line 97, in UpdateUserSettings
    if UserSettings.has_key("config"):UEditorSettings.update(UserSettings["config"])
AttributeError: 'dict' object has no attribute 'has_key'

 这个问题,需要我们修改settings.py,中相应的内容。修改如下:

#更新配置:从用户配置文件settings.py重新读入配置UEDITOR_SETTINGS,覆盖默认
def UpdateUserSettings():
    UserSettings=getattr(gSettings,"UEDITOR_SETTINGS",{}).copy()
    #if UserSettings.has_key("config"):UEditorSettings.update(UserSettings["config"])
    if UserSettings.get("config"):UEditorSettings.update(UserSettings["config"])
    #if UserSettings.has_key("upload"):UEditorUploadSettings.update(UserSettings["upload"])
    if UserSettings.get("upload"):UEditorUploadSettings.update(UserSettings["upload"])

#读取用户Settings文件并覆盖默认配置
UpdateUserSettings()


#取得配置项参数
def GetUeditorSettings(key,default=None):
    #if UEditorSettings.has_key(key):
    if UEditorSettings.get(key):
        return UEditorSettings[key]
    else:
        return default

 

修改完,还会继续报错:

ModuleNotFoundError: No module named 'settings'

    from .widgets import UEditorWidget, AdminUEditorWidget
  File "/root/.virtualenvs/abc_block_chain/lib/python3.6/site-packages/DjangoUeditor/widgets.py", line 9, in <module>
    from .commands import *
  File "/root/.virtualenvs/abc_block_chain/lib/python3.6/site-packages/DjangoUeditor/commands.py", line 3, in <module>
    import settings as USettings
ModuleNotFoundError: No module named 'settings'

看到是commands.py中,导入settings问题。解决办法跟上面的一样。

之后启动,正常。到此,Django 服务器安装相关UEditor 问题处理基本上就这样了。

猜你喜欢

转载自blog.csdn.net/u012798683/article/details/107320708

相关文章