Django运行服务器错误:不支持的操作数类型 '+=':'NoneType'和'str'。

3

我正在运行一个使用Django创建的本地开发项目。但是我无法启动开发服务器:

(Gaia_database_env)FakeComputer:gaia_database_proj FakeUser$ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/FakeUser/GoogleDrive/Sites/Gaia_database_env/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/FakeUser/GoogleDrive/Sites/Gaia_database_env/lib/python3.4/site-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/Users/FakeUser/GoogleDrive/Sites/Gaia_database_env/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/FakeUser/GoogleDrive/Sites/Gaia_database_env/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Users/FakeUser/GoogleDrive/Sites/Gaia_database_env/lib/python3.4/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/Users/FakeUser/GoogleDrive/Sites/Gaia_database_env/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/Users/FakeUser/GoogleDrive/Sites/Gaia_database_env/lib/python3.4/site-packages/tinymce/models.py", line 6, in <module>
    from tinymce import widgets as tinymce_widgets
  File "/Users/FakeUser/GoogleDrive/Sites/Gaia_database_env/lib/python3.4/site-packages/tinymce/widgets.py", line 10, in <module>
    import tinymce.settings
  File "/Users/FakeUser/GoogleDrive/Sites/Gaia_database_env/lib/python3.4/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 "/Users/FakeUser/GoogleDrive/Sites/Gaia_database_env/bin/../lib/python3.4/posixpath.py", line 82, in join
    path += b
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str

我正在使用虚拟环境,并安装了以下包:

(Gaia_database_env)FakeComputer:gaia_database_proj FakeUser$ pip freeze
Django==1.8.2
django-bootstrap3==6.1.0
django-tinymce==1.5.3
wheel==0.24.0

以下是我的settings.py文件:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'm6eu#pf_u$upk2qkizhp%gvc6wb%1(alhey8!hqkdzq%j%b4&('

# SECURITY WARNING: don't run with debug turned on in production!
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',
    'bootstrap3',
    'gaia_app'
)

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',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'gaia_database.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'gaia_database.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/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.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'CET'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'

有什么想法吗?谢谢。

@nu11p01n73R,老兄,如果你仔细读一下异常信息,就会发现他正在调用os.path.join函数。我认为告诉他path += b失败了并没有帮助,除非他想重写os.path.join函数。 - CrazyCasta
@Bakaburg,tinymce是你正在开发的应用程序还是别人制作的,你正在尝试使用它?我们可能需要查看tinymce/settings.py文件。 - CrazyCasta
所以问题不在posixpath.py!TinyMCE是一个相当常见的基于HTML5的富文本编辑器。我应该在settings.py中寻找什么? - Bakaburg
1
最好把它发布出来,这样我们就可以看到它。看起来settings.STATIC_ROOT是None,我猜这意味着settings没有被正确加载。 - CrazyCasta
1个回答

1
自Django 1.7以来,STATIC_ROOT默认为None,因此除非您已经设置了它,否则TinyMCE将无法正确地提供其JS文件。
你应该做以下两件事之一:
  • 设置TINYMCE_JS_ROOT
  • 设置STATIC_ROOT
现在,这些设置不会被使用,除非您还将TINYMCE_COMPRESSOR设置为True(它默认为False),因此如果您不知道它们是什么,我建议您暂时将TINYMCE_JS_ROOT设置为"tiny_mce"

TinyMCE文档提供了一些关于配置的信息,但它既不是非常准确也不是非常有帮助。实际运行的代码在这里,这里是JS_ROOT实际使用的地方


嗯...我在设置中添加了TINYMCE_JS_ROOT =“tiny_mce”,但没有任何变化。我也在我的问题中写下了我的设置。我想应该不只是写下tiny_mce的路径。但它在虚拟环境的Python文件夹中。我不认为我应该声明该文件夹的完整绝对路径... - Bakaburg

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接