Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用wagtail创建用于测试API的假数据库_Python_Django_Wagtail - Fatal编程技术网

Python 使用wagtail创建用于测试API的假数据库

Python 使用wagtail创建用于测试API的假数据库,python,django,wagtail,Python,Django,Wagtail,我需要针对我的API创建一些测试。 API使用摇摆页,并为我提供它们的内容。 我正在为测试创建数据库,但我无法创建摇摆页,因为我总是得到 ValidationError: {'path': [u'This field cannot be blank.'], 'depth': [u'This field cannot be null.']} 我怎么做?我必须创建从根到树的整个站点吗?深度-这是一个嵌套级别。根页面具有级别1,主页具有级别2,显然,只有1个页面可以位于第一级和第二级 path-这是

我需要针对我的API创建一些测试。 API使用摇摆页,并为我提供它们的内容。 我正在为测试创建数据库,但我无法创建摇摆页,因为我总是得到

ValidationError: {'path': [u'This field cannot be blank.'], 'depth': [u'This field cannot be null.']}

我怎么做?我必须创建从根到树的整个站点吗?

深度-这是一个嵌套级别。根页面具有级别1,主页具有级别2,显然,只有1个页面可以位于第一级和第二级

path
-这是一个特定的值,我还没有理解

根页面(
depth
=1)具有以下路径:
0001

第二个嵌套级别(
depth
=2)上的主页具有路径
0000001

第三嵌套级别(
depth
=3)上的第一页具有路径
00010001

我不能保证我给你的建议会奏效,因为我已经做了很长时间了, 但是,如果要在相同的嵌套级别生成假页面,只需更改路径,在最后一位数字上加+1,并保持深度不变

举例来说:

from yourapp.models import FakePage
k = 1
for i in range(5):
    k = k + 1
    page = FakePage(
    title = ('faketitle{}').format(k),
    path = ('{0:04}').format(k)
    depth = 3,
    )
    page.save()
但有一个更好的方法:

from wagtail.wagtailcore.models import Page
from yourapp.models import FakePage

pages = Page.objects.all() # Get all pages

page = Page.objects.get(pk=3) # For example, take a page with pk = 3

fakepage = FakePage(title='fakepage title') # Create the desired page

page.add_child(instance=fakepage) # Add children page to the parrent page
在这种情况下,您不需要担心深度和路径。

请提供一个答案。现在还不清楚你到底有什么问题。看起来您没有为http POST中的所有必填字段提供数据。