Opened 4 years ago

Closed 4 years ago

Last modified 2 years ago

#16504 closed New feature (wontfix)

PROJECT_ROOT ought to be in the generated project settings module

Reported by: pydanny Owned by: rvanhoepen
Component: Core (Other) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no


I see this used by a lot of people in a lot of projects. For experience developers they figure it out on their own. Beginning developers often miss it and hard code all their paths. This becomes a problem on deployment.

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

Possible alternative solution: Add this to an as-of-yet Django best practices page.

Attachments (1)

add_project_root_to_settings.diff (460 bytes) - added by rvanhoepen 4 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 4 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from PROJECT_ROOT ought to be a built-in django settings ref to PROJECT_ROOT ought to be in the generated project settings module
  • Triage Stage changed from Unreviewed to Design decision needed

Minor irony here, this is an incorrect example: you want to ensure you abspath before you dirname.

This could potentially just be a documentation note rather than part of the default generated settings module.
Perhaps you could bring this up on django-dev, Danny?

comment:2 Changed 4 years ago by rvanhoepen

  • Owner changed from nobody to rvanhoepen
  • Status changed from new to assigned

comment:3 Changed 4 years ago by rvanhoepen

  • Has patch set
  • Needs documentation set
  • Needs tests set
  • Triage Stage changed from Design decision needed to Ready for checkin

comment:4 Changed 4 years ago by aaugustin

  • Patch needs improvement set
  • Triage Stage changed from Ready for checkin to Design decision needed

Sorry to slow down your enthusiasm, but:

  • design decision needed means a core developer must accept or reject the idea; only a core developer can move a ticket from DDN to Accepted,
  • the patch must be reviewed by someone else before it can be marked as ready for checkin,
  • the patch can't be ready for checkin if it needs docs and tests.

See for more information about this process.

Regarding the patch itself:

  • You inserted an import between a comment and the line that is commented, so the comment no longer makes sense,
  • I don't understand why you set PROJECT_PATH to django/conf by default.

comment:5 Changed 4 years ago by rvanhoepen

Mmm... I understand... Sorry, I'm new to all of this :)

Updated to take PROJECT_ROOT out of django/conf/,
and uncommented it in django/conf/project_template/

Last edited 4 years ago by rvanhoepen (previous) (diff)

Changed 4 years ago by rvanhoepen

comment:6 Changed 4 years ago by aaugustin

With this addition, we could provide more sensible defaults: MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media') and STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static').

This would have prevented #16703.

comment:7 Changed 4 years ago by jezdez

  • Resolution set to wontfix
  • Status changed from assigned to closed

FTR, this has been proposed before and proven to be counter-productive. The "project" metaphor is only temporary and shouldn't be fortified in yet another setting.

comment:8 Changed 4 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

comment:9 Changed 2 years ago by mightyiam

I came here following, which is about an absolute path in the tutorial in the sqlite db filename.

I'm new to all of this and no where near design decisions.

But I would like to make a point that in the case of sqlite, relative url is very comfortable.


comment:10 Changed 2 years ago by aaugustin

The latest iteration of the default settings file created by startproject includes BASE_DIR, which is essentially the same as PROJECT_DIR, except the name is semantically correct.

Note: See TracTickets for help on using tickets.
Back to Top