Skip to main content
 首页 » 编程设计

python之Django 运行服务器错误 : unsupported operand type(s) for +=: 'NoneType' and 'str'

2025年05月04日12freeliver54

我正在运行一个用 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/' 

有什么想法吗??

谢谢

请您参考如下方法:

从 Django 1.7 开始,STATIC_ROOT 默认为 None,因此除非您设置它,否则 TinyMCE 将无法正确提供其 JS 文件。

你应该:

  • 设置TINYMCE_JS_ROOT
  • 设置STATIC_ROOT

现在,除非您还将 TINYMCE_COMPRESSOR 设置为 True(默认为 False),否则不会使用这些设置,所以如果您不知道它们是什么,我建议您暂时将 TINYMCE_JS_ROOT 设置为 "tiny_mce"。


TinyMCE documentation有一些关于配置的信息,但它既不准确也没有帮助。 actual code that runs在这里,here is where JS_ROOT is actually used .