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.3.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-app-router-0.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 b02fe68b30aac68fb6a0e6d1f0de115aea9022e551c9c4b9b43d9817253bffe6
MD5 9d45464bf5ec9d4cf541fdf8d63e68d8
BLAKE2b-256 07c8ca527b48d10602aa26e1fadfdce621c0186f3dd9cd55472295dceb9d84f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_app_router-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9681515e70347af7850628318b8aebf492c15ae6e8be18688bcbe76639eb8d18
MD5 be9e64fe89eb5e37cace97d1143d54af
BLAKE2b-256 de771a7fc5eb9e7983ba92aa2716d682addf2fd241c8e836f1a7fcc1d6d99333

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