Here's a quick summary of everything we released in Q1 2024.

Headless CMS for Django

Hygraph is the ideal Headless CMS for Django websites and applications. Read further to learn how our API-first CMS allows you to add components to your Django apps in minutes and enable your website's content to be managed from a powerful CMS instead of Django Admin.

Step #1 - Create a view function to fetch the data from Hygraph

To query Hygraphs GraphQL Content API from a Django application you would send an HTTP POST request to the Hygraph's endpoint. On the right is a basic example of how to do this using the popular requests library in Python. Please ensure you have requests installed in your Django project (pip install requests).

In addition, you will need to define the URL pattern in your urls.py to point to this view function.

import requests
from django.http import JsonResponse
from django.shortcuts import render
def graphql_query(request):
url = 'https://api-<region>.hygraph.com/v2/<some hash>/master'
token = 'YOUR_HYGRAPH_TOKEN'
query = """
query MyQuery {
products {
slug
name
description
availability
image {
url
}
}
}
"""
headers = {
'Authorization': 'Bearer your-token-here',
}
response = requests.post(url, json={'query': query}, headers=headers)
data = response.json()['data']['myQuery']
return render(request, 'products_template.html', {'data': data})

Step #2 - Work with data within Django templates

In a Django template, displaying product details from a GraphQL query involves iterating over a list of products and rendering HTML elements populated with product attributes. Each product's name, description, image, and availability are presented in a structured layout.

products_template.html
<h1>Our Products</h1>
{% if products %}
<div class="product-list">
{% for product in products %}
<div class="product">
<a href="/product/{{ product.slug }}">
<h2>{{ product.name }}</h2>
<p>{{ product.description }}</p>
{% if product.image %}
<img src="{{ product.image }}" alt="{{ product.name }}" />
{% endif %}
<p>Availability: {{ product.availability|yesno:"Available,Out of stock" }}</p>
</a>
</div>
{% endfor %}
</div>
{% else %}
<p>No products available.</p>
{% endif %}

Start building with Django

We made it really easy to set up your project in Hygraph and use our GraphQL API within your Django project.

Quickstart

Take a look at our docs to see how you can easily set up a project in Hygraph and use it for your Django project.

Learn GraphQL

Hygraph is GraphQL-native Headless CMS offers precise data retrieval, minimizing over-fetching and optimizing efficiency.

Examples

Look at some of the example projects to see Hygraph in action.

Why Hygraph

Choosing Hygraph for your Django project

Integrating a GraphQL-native headless CMS with Django supersedes the traditional Django admin by providing a more tailored content management interface and delivering content via GraphQL's efficient queries. In addition, a headless CMS can serve as a replacement for a database without the need to manage models and relations in a typical Django fashion.

This setup streamlines content updates and optimizes content delivery, thus enhancing performance and developer experience.

headless cms for django

Developer Experience

We try to be the most un-opinionated CMS on the market with a wide collection of open source example projects to get you started.

Headless CMS

As a headless CMS (i.e. API based content management), you can be as modular and flexible as you need. We even support multiplatform content management.

Management API

Hygraph boasts a flexible and powerful management API to manage your content and schema, as well as a blazing fast content API.

Get started for free, or request a demo to discuss larger projects