Skip to main content

Django App Router

A library for creating routes in Django with a similar structure to Next.js App Router.

Releases Stars Issues

Features

  • Dynamic routing
  • Nested routing
  • Route parameters
  • Route groups

Requirements

  • Python 3.8+
  • Django 4.2+

Installing

Windows:

$ pip install -U django-app-router

Linux/MacOS:

$ python3 -m pip install -U django-app-router

Setup and Usage

urls.py:

from django_app_router import routers

router = routers.AppRouter()
router.include_app('your_app') # app directory name

urlpatterns = [
    # ...
]

urlpatterns += router.urls

Alternatively, you can use the include function. like this:

urlpatterns = [
    # ...
    path('', include(router.urls)),
]

Example

for example, define a route with the file page.py in the routers folder:

from django.shortcuts import render

def page(request):
    """home"""
    # You can also name the page
    # path(..., ..., name='home')

    return render(request, 'page.html')
Route Example URL params
routers/page.py / {}
routers/info/page.py /info/ {}
routers/(group)/about/page.py /about/ {}
routers/user/[slug]/page.py /user/1/ {'slug': 1}

Example folder structure

your_app
├── migrations
│   └── __init__.py
├── routers
│   ├── (auth)
│   │   ├── login
│   │   │   ├── page.html
│   │   │   └── page.py
│   │   └── register
│   │       ├── page.html
│   │       └── page.py
│   ├── info
│   │   └── page.py
│   ├── user
│   │   └── [user_id]
│   │       ├── page.html
│   │       └── page.py
│   ├── layout.html
│   ├── page.html
│   └── page.py
├── __init__.py
├── admin.py
├── apps.py
├── models.py
├── tests.py
├── urls.py
└── views.py

You can see the full example in the example folder.

Notes

if you have .html files in the routers directory. ensure that the DIRS setting in the TEMPLATES setting includes the routers directory.

TEMPLATES = [
    {
        # ...
        'DIRS': [
            # any other directories
            BASE_DIR / 'your_app' / 'routers',
        ],
        # ...
    },
]

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for django-app-router 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-app-router 0.1.1
File Size Uploaded Provenance Actions
django-app-router-0.1.1.tar.gz 6.9 kB Without provenance Details for django-app-router-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-app-router 0.1.1
File Interpreter ABI Platform Actions
django_app_router-0.1.1-py3-none-any.whl Python 3 none any Details for django_app_router-0.1.1-py3-none-any.whl

Total release size: 13.9 kB

Release files / django-app-router-0.1.1.tar.gz

Download URL django-app-router-0.1.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ff4e0da9c24ffa6987d88590c1a14ac982e8402d912e22c3ba4a2441b16a48c2
BLAKE2b-256 checksum
How to use checksums
23e654bdf9f6b44b762a6cff835437ef27fd2e6e18e9306fe15960aeec4264fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release files / django_app_router-0.1.1-py3-none-any.whl

Download URL django_app_router-0.1.1-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c0cc81536b7de412a0141d6a9bcf842ec216c548acbf0822c53192efaed007b
BLAKE2b-256 checksum
How to use checksums
06a546542c6dd137647d8deed508a38814f53490f6d70231c2266915eaa04b5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Security for django-app-router 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page