【问题标题】:Django TypeError after installing tinymce安装 tinymce 后出现 Django TypeError
【发布时间】:2015-01-10 15:11:40
【问题描述】:

在安装 tinymce 并将其包含在 settings.py 中的 INSTALLED_APPS 之后,当我尝试运行本地服务器时出现此错误:

(django) \mypath\ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\venv\django\lib\site-packages\django\core\management\__init__.py", line 385, in execute_f
rom_command_line
    utility.execute()
  File "C:\venv\django\lib\site-packages\django\core\management\__init__.py", line 354, in execute
    django.setup()
  File "C:\venv\django\lib\site-packages\django\__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\venv\django\lib\site-packages\django\apps\registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "C:\venv\django\lib\site-packages\django\apps\config.py", line 197, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\venv\django\lib\site-packages\tinymce\models.py", line 6, in <module>
    from tinymce import widgets as tinymce_widgets
  File "C:\venv\django\lib\site-packages\tinymce\widgets.py", line 10, in <module>
    import tinymce.settings
  File "C:\venv\django\lib\site-packages\tinymce\settings.py", line 16, in <module>
    JS_ROOT = getattr(settings, 'TINYMCE_JS_ROOT',os.path.join(settings.STATIC_ROOT, 'tiny_mce'))
  File "C:\venv\django\lib\ntpath.py", line 64, in join
    result_drive, result_path = splitdrive(path)
  File "C:\venv\django\lib\ntpath.py", line 114, in splitdrive
    if len(p) > 1:
TypeError: object of type 'NoneType' has no len()

我不知道发生了什么,因为我什至没有开始弄乱文件以在项目中实际使用 tinymce。当我简单地从 INSTALLED_APPS 中删除“tinymce”时,它会恢复正常,但问题是我真的需要 tinymce。我多次确保 tinymce 是用 pip 安装的。这是我的 settings.py 的样子:

"""
Django settings for mysite project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '***'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'tinymce',
    'interface',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    "django.core.context_processors.tz",
    "django.contrib.messages.context_processors.messages",
    "interface.context_processor.global_vars"
)

ROOT_URLCONF = 'mysite.urls'

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'

如果有任何帮助,我将不胜感激,在此先感谢。

【问题讨论】:

    标签: python django tinymce typeerror nonetype


    【解决方案1】:

    看来您需要在 settings.py 中设置 STATIC_ROOT/URL。

    【讨论】:

    • 谢谢!我实际上认为只需要其中一个,但事实证明它们都是必需的
    【解决方案2】:

    尝试在 settings.py 中将 TINYMCE_JS_ROOT 设置为 tinymce js 文件夹。从您的错误输出中我可以看出,此设置丢失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多