我正在尝试编写一个CMS内容迁移脚本,该脚本将为django-cms创建我们的页面。然而,即使使用Django-cms的默认安装,Django-treebeard也会不断提出异常,而且我不清楚为什么会这样做。
例如,执行此行时:
api.create_page(title="Hello world",
language='en',
parent=None)
我的脚本总是在这里(第307-8行)在来自treebeard的mp_tree.py(v 4.1.0)中失败:
if newobj.pk:
raise NodeAlreadySaved("Attempted to add a tree node that is "\
"already in the database")
有没有人有一个关于如何使用cms.api.create_page()方法的非常简单的例子?
Pip冻结显示以下版本:
aldryn-apphooks-config==0.2.7
aldryn-boilerplates==0.7.4
aldryn-common==1.0.4
aldryn-faq==1.2.2
aldryn-forms==2.1.3
aldryn-reversion==1.0.9
aldryn-search==0.3.0
aldryn-translation-tools==0.2.1
appdirs==1.4.3
boto==2.46.1
boto3==1.4.4
botocore==1.5.26
cmsplugin-filer==1.1.3
contextlib2==0.5.4
cssselect==1.0.0
cssutils==1.0.1
dj-database-url==0.4.1
Django==1.8.17
django-absolute==0.3
django-admin-sortable==2.0.21
django-admin-sortable2==0.6.6
django-appconf==1.0.2
django-appdata==0.1.6
django-cas-ng==3.5.6
django-classy-tags==0.8.0
django-cms==3.4.1
django-cors-headers==2.0.2
django-debug-toolbar==1.7
django-emailit==0.2.2
django-environ==0.4.1
django-extensions==1.7.7
django-filer==1.2.5
django-formtools==1.0
django-haystack==2.5.1
django-mptt==0.8.6
django-parler==1.6.5
django-polymorphic==0.8.1
django-reversion==1.10.2
django-sekizai==0.10.0
Django-Select2==4.3.2
django-simple-captcha==0.5.3
django-sizefield==0.9.1
django-sortedm2m==1.3.2
django-spurl==0.6.4
django-standard-form==1.1.1
-e git+https://github.com/jschneier/django-storages.git@043b91b10ebfebdf7e752d743ae630f0daa2c4f4#egg=django_storages
django-storages-redux==1.3.2
django-tablib==3.1.2
django-taggit==0.21.3
django-treebeard==4.1.0
djangocms-admin-style==1.2.6.2
djangocms-attributes-field==0.1.2
djangocms-column==1.7.0
djangocms-googlemap==1.0.1
djangocms-installer==0.9.3
djangocms-link==2.0.3
djangocms-rest-api==0.2.0
djangocms-snippet==1.9.2
djangocms-style==2.0.1
djangocms-text-ckeditor==3.3.1
djangocms-video==2.0.3
djangorestframework==3.4.7
docutils==0.13.1
easy-thumbnails==2.3
google-auth==0.8.0
google-auth-httplib2==0.0.2
google-cloud-core==0.23.1
google-cloud-storage==0.23.1
googleapis-common-protos==1.5.2
html5lib==0.9999999
httplib2==0.10.3
jmespath==0.9.0
lxml==3.7.0
mysqlclient==1.3.10
packaging==16.8
Pillow==3.4.2
premailer==3.0.1
protobuf==3.2.0
psycopg2==2.6.2
pyasn1==0.2.3
pyasn1-modules==0.0.8
pyparsing==2.2.0
python-cas==1.2.0
python-dateutil==2.6.0
python-slugify==1.2.0
pytz==2016.10
raven==6.0.0
requests==2.12.3
rsa==3.4.2
s3transfer==0.1.10
six==1.10.0
sqlparse==0.2.3
tablib==0.11.3
tzlocal==1.3
Unidecode==0.4.19
URLObject==2.4.2
YURL==0.13
答案 0 :(得分:1)
感谢@dentemm和@paulo,我能够在Python shell中运行如下:
>>> from cms import constants
>>> from cms.constants import TEMPLATE_INHERITANCE_MAGIC
>>> from cms import api
>>> api.create_page(title="Hello World4",language='en',template=TEMPLATE_INHERITANCE_MAGIC,parent=None)
<cms.models.pagemodel.Page object at 0x102b674e0>
它失败了,因为我没有包括“模板”#39;论证和必要的进口。
答案 1 :(得分:0)
我不确定这是否是导致您出现问题的原因,但上面的api.create_page()代码中存在错误: parent =无不应包含空格。