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

406
Vistas
Django new version 3.1, the settings file have some changes

On Django new version 3.1, the settings file have some changes, and I came to ask how I have to proceed to set my static files? The way that I usually did doesn't work more.

Last versions:

import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Version 3.1:

from pathlib import Path
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent

I usually set my static files like this:

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media_root')

If I insert the import os will work, but is it the right practice? What is the best practice to set this? Thank you?

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

0

STATIC_ROOT = BASE_DIR.parent / "static_cdn"

try this if you want to add your STATIC_ROOT inside environment directory

over 4 years ago · Santiago Trujillo Denunciar

0

This change makes it a lot easier for you to define your STATIC and MEDIA variables. You don't even need to import os for this purpose and all you need is to add following codes to your settings.py:

BASE_DIR = Path(__file__).resolve(strict=True).parent.parent # which shows the root directory of your project

STATIC_ROOT = BASE_DIR / 'static' # is equal to os.path.join(BASE_DIR, 'static/')
STATIC_URL = '/static/'

MEDIA_ROOT = BASE_DIR / 'media' # is equal to os.path.join(BASE_DIR, 'media/')
MEDIA_URL = '/media/'
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