Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
Django need first paragraph

I created model with my posts. file blog/models.py:

import datetime

from ckeditor.fields import RichTextField
from django.db import models


class Post(models.Model):
    name = models.CharField(max_length=250)
    content = RichTextField()
    date = models.DateField(default=datetime.date.today)

and in db i has this record:

<p>First paragraph</p>

<p>Second paragraph</p>

<p>Third paragraph</p>

<p>etc</p>

<p>...</p>

How I can get result First paragraph ONLY

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You could work with BeautifulSoup and make a property that will return the HTML content of the first paragraph. You first install beautifulsoup with:

pip3 install beautifulsoup4

then we can define a property that implements logic to extract the first <p> tag:

from bs4 import BeautifulSoup

class Post(models.Model):
    name = models.CharField(max_length=250)
    content = RichTextField()
    date = models.DateField(auto_now_add=True)

    def first_paragraph(self):
        bs = BeautifulSoup(self.content)
        return str(bs.find('p'))
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda