django ImportError:没有名为tiny-mce的模块

时间:2016-03-02 07:50:10

标签: javascript python django tinymce django-tinymce

我正在运行django 1.7.2和python 2.7。

我有一个测试表单,我想将django-tinymce添加到我的文本区域。

我已按照教程here安装了django-tinymce。

但是,当我尝试运行服务器时,我在本地开发服务器上收到以下错误:

ImportError: No module named tiny-mce

以下是我安装django-tinymce的步骤:

  1. 将应用程序安装到我项目的虚拟环境中。

    pip install django-tinymce
    
  2. 我通过运行pip freeze(django-tinymce == 2.2.0)确认了上述安装。

  3. 然后我将'tinymce',添加到我的INSTALLED_APPS

  4. 然后我将(r'^tinymce/', include('tinymce.urls')),添加到了我的网址。

  5. 然后我将tinymce js文件添加到我的插件中并在我的base.html文件中引用了该文件:

    <script src="{{ STATIC_URL }}plugins/tinymce/tinymce.min.js"></script>

  6. 我已将以下代码添加到我的settings.py文件中:

    TINYMCE_JS_URL = os.path.join(STATIC_URL, 'plugins/tinymce/tinymce.min.js')
    TINYMCE_DEFAULT_CONFIG = {
        'plugins' :'table, spellchecker, paste, searchreplace',
        'theme' : "advanced",
        'cleanup_on_startup ':True ,
        'custom_undo_redo_levels':10 ,
    }
    TINYMCE_SPELLCHECKER = True
    TINYMCE_COMPRESSOR = True
    

    我已经仔细检查过我已经正确地将django-tinymce安装到了正确的虚拟环境中。

    我搜索了Google和SO,但是当我尝试运行本地开发服务器时,我很难解决如何解决错误:

    ImportError:没有名为tiny-mce的模块

    编辑

    以下是表单代码:

    from tinymce.widgets import TinyMCE
    ....
    class SummaryDetailsForm(forms.ModelForm):
    
        required_css_class = 'required'
    
        def __init__(self, available_languages, language_preference, *args, **kwargs):
            """
            available_languages should be a valid choices list
            """
            super(SummaryDetailsForm, self).__init__(*args, **kwargs)
            self.fields['language_code'] = forms.ChoiceField(choices=available_languages, initial=language_preference, label=_('Language'),)
            summary_details = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
    
        class Meta:
            model = SummaryDetails
    

    以下是完整的追溯:

    Traceback (most recent call last):
      File "manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "C:\Users\6233114\desktop\zoodal\env\lib\site-packages\django\core\manage
    ment\__init__.py", line 385, in execute_from_command_line
        utility.execute()
      File "C:\Users\6233114\desktop\zoodal\env\lib\site-packages\django\core\manage
    ment\__init__.py", line 354, in execute
        django.setup()
      File "C:\Users\6233114\desktop\zoodal\env\lib\site-packages\django\__init__.py
    ", line 21, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "C:\Users\6233114\desktop\zoodal\env\lib\site-packages\django\apps\regist
    ry.py", line 85, in populate
        app_config = AppConfig.create(entry)
      File "C:\Users\6233114\desktop\zoodal\env\lib\site-packages\django\apps\config
    .py", line 87, in create
        module = import_module(entry)
      File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
        __import__(name)
    ImportError: No module named tiny-mce
    

1 个答案:

答案 0 :(得分:3)

您似乎已将'tiny-mce'而不是'tinymce'添加到INSTALLED_APPS