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

Installing

Python 3.12 or higher is required

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-app-router-0.0.2.tar.gz
  • Upload date:
  • Size: 5.0 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.2.tar.gz
Algorithm Hash digest
SHA256 3afc2f73d98a9c3e6a46c0abb168e08d399bcb8893d14a746478b8d226b581cd
MD5 b2bc3ffd60861656d73d5d2cf8bf1bcc
BLAKE2b-256 058289c82ee933b7fa54eeef9d5419eeb9583800ca99a80c47af0fb474fc51ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_app_router-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab33f00e6981ae4389dfb8bf13307b4607c4a7ca129b0655ad78dd4d3f0de9d8
MD5 eeb26f9888d30cf95079662434d5fdb8
BLAKE2b-256 6ce14c12e69b6d17e6d444f89bb28ecb705feecb6dc7815c2b66f935142f9af1

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