You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2.4 KiB


Graphene-Django takes a few seconds to install and set up.


Graphene-Django currently supports the following versions of Django:

  • >= Django 2.2


pip install graphene-django

We strongly recommend pinning against a specific version of Graphene-Django because new versions could introduce breaking changes to your project.

Add graphene_django to the INSTALLED_APPS in the file of your Django project:

    "django.contrib.staticfiles", # Required for GraphiQL

We need to add a graphql URL to the of your Django project:

For Django 2.2 and above:

from django.urls import path
from graphene_django.views import GraphQLView

urlpatterns = [
    # ...
    path("graphql", GraphQLView.as_view(graphiql=True)),

(Change graphiql=True to graphiql=False if you do not want to use the GraphiQL API browser.)

Finally, define the schema location for Graphene in the file of your Django project:

    "SCHEMA": "django_root.schema.schema"

Where path.schema.schema is the location of the Schema object in your Django project.

The most basic looks like this:

import graphene

class Query(graphene.ObjectType):
    hello = graphene.String(default_value="Hi!")

schema = graphene.Schema(query=Query)

To learn how to extend the schema object for your project, read the basic tutorial.

CSRF exempt

If you have enabled CSRF protection in your Django app you will find that it prevents your API clients from POSTing to the graphql endpoint. You can either update your API client to pass the CSRF token with each request (the Django docs have a guide on how to do that: or you can exempt your Graphql endpoint from CSRF protection by wrapping the GraphQLView with the csrf_exempt decorator:


from django.urls import path
from django.views.decorators.csrf import csrf_exempt

from graphene_django.views import GraphQLView

urlpatterns = [
    # ...
    path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=True))),