Skip to content

Comments

Add BARE setting for minimal database-free apps#88

Open
SmileyChris wants to merge 2 commits intoradiac:mainfrom
SmileyChris:bare-mode
Open

Add BARE setting for minimal database-free apps#88
SmileyChris wants to merge 2 commits intoradiac:mainfrom
SmileyChris:bare-mode

Conversation

@SmileyChris
Copy link
Contributor

Summary

  • Add BARE=True setting for lightweight apps that don't need persistent storage or authentication
  • Make STATICFILES_DIRS conditional on the directory existing

BARE mode features

When BARE=True is set:

  • Cookie-based sessions (signed_cookies backend)
  • Cookie-based messages (CookieStorage)
  • In-memory SQLite database by default
  • No auth, admin, or contenttypes apps installed
  • Middleware and context processors adapt to installed apps
  • Skips migrations and superuser prompts on startup

Example usage

from nanodjango import Django

app = Django(BARE=True)

@app.route("/")
def index(request):
    count = request.session.get("count", 0) + 1
    request.session["count"] = count
    return f"Visit count: {count}"

Test plan

  • All existing tests pass (90/91, 1 pre-existing failure unrelated to this PR)
  • New tests for BARE mode settings verification
  • New tests for cookie-based sessions and messages
  • New test for STATICFILES_DIRS behavior

Only include static/ in STATICFILES_DIRS if the directory actually
exists. This prevents warnings and allows apps in directories without
a static/ folder to work cleanly.
BARE=True configures nanodjango for lightweight apps that don't need
persistent storage or authentication:

- Cookie-based sessions (signed_cookies backend)
- Cookie-based messages (CookieStorage)
- In-memory SQLite database by default
- No auth, admin, or contenttypes apps
- Middleware and context processors adapt to installed apps
- Skips migrations and superuser prompts on startup

Also moves admin/auth imports to be lazy to avoid errors when these
apps aren't installed.

Includes example app and comprehensive tests.
@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 59.45946% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.00%. Comparing base (e91c6e3) to head (0497e01).

Files with missing lines Patch % Lines
nanodjango/app.py 0.00% 12 Missing ⚠️
nanodjango/settings.py 88.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #88      +/-   ##
==========================================
+ Coverage   47.79%   48.00%   +0.21%     
==========================================
  Files          26       26              
  Lines        1904     1931      +27     
==========================================
+ Hits          910      927      +17     
- Misses        994     1004      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant