我有一个这样的模型....
class Person(models.Model):
name = models.CharField(max_length=55,null=False, blank=False)
parent = models.ForeignKey('Person.Person', null=False, blank=False)
Run Code Online (Sandbox Code Playgroud)
我想创建一个递归函数,最终将返回整个人家谱的字典....
所以例如......
first_person = Person.objects.filter(name='FirstPerson')
family_tree = GetChildren(first_person)
Run Code Online (Sandbox Code Playgroud)
GetChildren是我的递归函数,它将不断调用GetChildren,直到没有更多的子项......它应该返回一个包含所有这些子项的字典,如此...
{
'name': 'FirstPerson',
'children': [
{
'name': 'FirstPersonChild1'
'children': [ ... ]
},
{
'name': 'FirstPersonChild2'
'children': [ ... ]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我从来没有善于递归,有人会介意如何解决这个问题......
我正在制作一个网站,根据不同的场景进行大量的PHP重定向..就像这样......
header("Location: somesite.com/redirectedpage.php");
Run Code Online (Sandbox Code Playgroud)
出于证券的考虑,我只是想彻底了解重定向的工作原理.我的问题是,在此标头调用之后PHP是否继续执行?
例如......回声是否仍然在这段代码中执行?
function Redirect($URL)
{
header("Location: " . $URL);
}
Redirect("http://somesite.com/redirectedpage.php");
echo("Code still executed");
Run Code Online (Sandbox Code Playgroud)
如果是这样......我会将Redirect功能更改为此...使回显不执行但仍然重定向?
function Redirect($URL)
{
header("Location: " . $URL);
exit(1);
}
Redirect("http://somesite.com/redirectedpage.php");
echo("Code still executed");
Run Code Online (Sandbox Code Playgroud)
出于证券的考虑,我只是想彻底了解重定向的工作原理.