Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

399
Views
Django nueva versión 3.1, el archivo de configuración tiene algunos cambios

En la nueva versión 3.1 de Django, el archivo de configuración tiene algunos cambios, y vine a preguntar cómo debo proceder para configurar mis archivos estáticos. La forma en que solía hacerlo no funciona más.

Últimas versiones:

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

Versión 3.1:

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

Por lo general, configuro mis archivos estáticos de esta manera:

 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')

Si inserto el import os , funcionará, pero ¿es la práctica correcta? ¿Cuál es la mejor práctica para establecer esto? ¿Gracias?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

STATIC_ROOT = BASE_DIR.parent / "static_cdn"

intente esto si desea agregar su STATIC_ROOT dentro del directorio de entorno

over 4 years ago · Santiago Trujillo Report

0

Este cambio le facilita mucho la definición de sus variables STATIC y MEDIA . Ni siquiera necesita importar el os para este propósito y todo lo que necesita es agregar los siguientes códigos a su 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!