Skip to main content

A simple Django app to route requests, Inspired by Next.js App Router.

Project description

django app router

A modern, easy to use, and powerful router for Django apps. Inspired by the Next.js app router.

Django App Router

Features

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

Requirements

  • Python 3.8+
  • Django 4.2+

Note Not tested with other versions.

Installing

Windows:

$ pip install -U django-app-router

Linux/MacOS:

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

Setup and Usage

<app_name>/urls.py:

from pathlib import Path

import django_app_router

urlpatterns = [
    # Your other urlpatterns
]

urlpatterns += django_app_router.init(
    # The path to the templates folder
    Path(__file__).resolve().parent / 'templates',
)

Example

for example, define a route with the file page.py in the templates 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
templates/page.py / {}
templates/info/page.py /info/ {}
templates/(group)/about/page.py /about/ {}
templates/user/[slug]/page.py /user/1/ {'slug': 1}

Example folder structure

app
├── migrations
│   └── __init__.py
├── templates
│   ├── (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.

License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-app-router-0.0.4.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

django_app_router-0.0.4-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file django-app-router-0.0.4.tar.gz.

File metadata

  • Download URL: django-app-router-0.0.4.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for django-app-router-0.0.4.tar.gz
Algorithm Hash digest
SHA256 2ab42bf47f2638e978d22771a25a36ce568eb636828f1cde0a3cf2e2daafb40c
MD5 ee1189d4f609c69d0f5b578ac1001ade
BLAKE2b-256 5a2b90d62f5a5e716a27eb73c387a964051fcdb604c73f662cb4718022ea5369

See more details on using hashes here.

File details

Details for the file django_app_router-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_app_router-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 662e41693ffec441a290d3542925a2b796ac3320b2c55dab3da200c7209c4737
MD5 af884ad57f1738f2f68bf1f4d048cd34
BLAKE2b-256 a81bd37783916e86aab81a9d1bb7b9b4377541d86cd813f104adba5228292521

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page