You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django项目配置根目录(含settings.py等)是否有命名规范?

Django Configuration Root Directory: Naming Best Practices

Great question — that nested duplicate project name structure from the official tutorial does get clunky, especially as projects grow. Let’s talk about the common naming conventions the Django community uses to fix this.

First, let’s recap: we’re referring to the directory that holds settings.py, wsgi.py, urls.py (what Two Scoops of Django calls the "configuration root"). The default django-admin startproject setup creates a nested directory with the same name as your project, leading to that confusing mysite/mysite/ structure you mentioned.

Here are the most widely adopted naming choices, ordered by popularity in the community:

  • config/: This is the gold standard recommended by Two Scoops of Django and used in most production-ready projects. It’s explicit, immediately tells everyone this is where core configuration lives, and eliminates the redundant project name nesting. Your structure would look like this:
    mysite/
        manage.py
        config/
            __init__.py
            settings.py
            urls.py
            wsgi.py
        app1/
        app2/
    
  • project/: A straightforward alternative that makes it clear this directory contains project-level (not app-level) code and config. It’s less ambiguous than reusing the project name, and works well for teams who prefer plain, intuitive terminology.
  • core/: Some teams opt for this when they want to bundle core project utilities (like base models, global middleware, or helper functions) alongside configuration files. It signals that this is the "heart" of the project, not just settings.

It’s important to note that there’s no official Django-enforced standard, but config/ has become the de facto choice because of its clarity. The key is to pick a name that makes sense for your team, document it, and stick with it consistently across the project.

If you switch from the default nested structure, don’t forget to update the import paths in manage.py and your WSGI/ASGI files. For example, in manage.py, you’d change DJANGO_SETTINGS_MODULE from mysite.settings to config.settings, and adjust the corresponding import statements.

内容的提问来源于stack exchange,提问作者Zach Valenta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:32:46