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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django_app_router-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab33f00e6981ae4389dfb8bf13307b4607c4a7ca129b0655ad78dd4d3f0de9d8 |
|
MD5 | eeb26f9888d30cf95079662434d5fdb8 |
|
BLAKE2b-256 | 6ce14c12e69b6d17e6d444f89bb28ecb705feecb6dc7815c2b66f935142f9af1 |