我只是在做教程@ https://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/来理解 Django 2 中的 graphQL 和 graphene。
我有一段时间没用过 Django,tut 似乎适用于 Django 11。当我尝试这样的 GraphQL 查询时,我得到了一个 CSRF_FAILURE_VIEW:
query {
allIngredients {
id
name
}
}
底层 json 夹具如下所示:
[{"model": "ingredients.category", "pk": 1, "fields": {"name": "Dairy"}}, {"model": "ingredients.category", "pk": 2, "fields": {"name": "Meat"}}, {"model": "ingredients.ingredient", "pk": 1, "fields": {"name": "Eggs", "notes": "Good old eggs", "category": 1}}, {"model": "ingredients.ingredient", "pk": 2, "fields": {"name": "Milk", "notes": "Comes from a cow", "category": 1}}, {"model": "ingredients.ingredient", "pk": 3, "fields": {"name": "Beef", "notes": "Much like milk, this comes from a cow", "category": 2}}, {"model": "ingredients.ingredient", "pk": 4, "fields": {"name": "Chicken", "notes": "Definitely doesn't come from a cow", "category": 2}}]
原谅一个菜鸟,但 Django 2 一定有什么改变?我需要应用其他设置吗?
在 settings.py 我有:
GRAPHENE = {
'SCHEMA': 'cookbook.schema.schema'
}
我的文件夹结构与 tut 略有不同,因为我的配料应用程序没有嵌套在我的食谱应用程序中。食谱应用程序是主应用程序,如下所示: