Django Broken Pipe Message

Viewed 3544

When creating an instance in Django Admin, I get the 'Broken pipe' message in the terminal. The instance can be seen in Django Admin and everything seems to be okay. Is this something that I can ignore or is there something wrong with my models?

models.py

from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from mptt.models import MPTTModel, TreeForeignKey


class Category(MPTTModel):
    name = models.CharField(
        verbose_name=_("Category"),
        max_length=255,
        unique=True,
    )
    slug = models.SlugField(verbose_name=_("Category URL"), max_length=255, unique=True)
    parent = TreeForeignKey("self", on_delete=models.CASCADE, null=True, blank=True, related_name="children")
    

    class MPTTMeta:
        order_insertion_by = ["name"]

    class Meta:
        verbose_name = _("Category")
        verbose_name_plural = _("Categories")

    def get_absolute_url(self):
        return reverse("store:category_all", args={self.slug})

    def __str__(self):
        return self.name

class Product(models.Model):
    category = models.ForeignKey(Category, on_delete=models.RESTRICT)
    title = models.CharField(
        verbose_name=_("title"),
        max_length=255,
    )
    description = models.TextField(verbose_name=_("description"), blank=True)
    slug = models.SlugField(max_length=255)
    price = models.DecimalField(
        verbose_name=_("Price"),
        max_digits=5,
        decimal_places=2,
    )
    created_at = models.DateTimeField(_("Created at"), auto_now_add=True, editable=False)
    updated_at = models.DateTimeField(_("Updated at"), auto_now=True)

    class Meta:
        verbose_name = _("Product")
        verbose_name_plural = _("Products")

    def get_absolute_url(self):
        return reverse("store:prod_details", args=[self.slug])

    def __str__(self):
        return self.title

Terminal

[03/Jul/2021 12:29:24] "POST /admin/store/category/add/ HTTP/1.1" 302 0
[03/Jul/2021 12:29:24] "GET /admin/store/category/ HTTP/1.1" 200 8094
[03/Jul/2021 12:29:24] "GET /admin/jsi18n/ HTTP/1.1" 200 3195
[03/Jul/2021 12:29:24] - Broken pipe from ('127.0.0.1', 67866)
1 Answers

After reading this Django Ticket and several stack overflow answers, I understand that a 'broken pipe' error occurs when the browser sends a request but does not wait for the response and closes the connection.

In my case, my React app was reloading the page immediately after sending the request. I just put preventDefault(); to prevent the app from refreshing and listen to the response.

Whatever stack you are using, make sure your app is available to accept the response from the server.

Related