gpt4 book ai didi

python - 如何使用 django-cms Python api 创建页面?

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:35 25 4
gpt4 key购买 nike

我正在尝试编写一个 CMS 内容迁移脚本,该脚本将为 django-cms 创建页面。然而,即使默认安装 Django-cms,Django-treebeard 仍然会引发异常,我不清楚为什么。

例如,当执行此行时:

api.create_page(title="Hello world",
language='en',
parent=None)

我的脚本总是在来自treebeard的mp_tree.py(v 4.1.0)中失败(第307-8行):

if newobj.pk:
raise NodeAlreadySaved("Attempted to add a tree node that is "\
"already in the database")

有人有一个关于如何使用 cms.api.create_page() 方法的非常简单的示例吗?

http://docs.django-cms.org/en/release-3.4.x/reference/api_references.html?highlight=create_page#cms.api.create_page

Pip freeze 显示这些版本:

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

最佳答案

感谢 @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>

它失败了,因为我没有包含"template"参数和必要的导入。

关于python - 如何使用 django-cms Python api 创建页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43310070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com