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
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
<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
File details
Details for the file django-app-router-0.0.5.tar.gz
.
File metadata
- Download URL: django-app-router-0.0.5.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2c0d242c0737e80ab50144ae84ef13a957db32f0e719690d0b51d6a81b0d17b |
|
MD5 | 8131c7dce2ab881ea95892d05e4a45d9 |
|
BLAKE2b-256 | c3cfe9b7108d5af7297f079952709dcc8032d87ae23d0b6ab71ddb16879c66ed |
File details
Details for the file django_app_router-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: django_app_router-0.0.5-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3e85822718eb416bae714811c01daa7c9b805b6c401bc614f1ce8a2ddc89f5a |
|
MD5 | 3d8a345e8a46c9c5963227316dd0ccd6 |
|
BLAKE2b-256 | c23d48c3e9808d1ecbbfc7907cf90e4232b7c8633fe415652d35cafc0d114822 |