duck.urlsยถ
โ Functions for easy creation and organization of url patterns data.
Example usage:
# urls.py
from duck.urls import path, re_path
from duck.shortcuts import render
from duck.http.response import HttpResponse
def home_view(request):
return HttpResponse("Hello world")
def profile_view(request, user_id):
return render('profile.html', request, context={'user_id': user_id})
def documents_view(request):
return f"Document {request.path}"
urlpatterns = [
path('/', home_view, name='home', methods=['GET']),
path("/user/<user_id>/profile", profile_view, name='profile'),
re_path('/doc/.*', documents_view, name='docs', methods=['GET'])
]
Module Contentsยถ
Classesยถ
A custom dictionary to represent a URL pattern. It allows easy access to URL, handler, name, and methods. |
Functionsยถ
Function to easily store urlpattern data for easy Route registration |
|
Function to easily store urlpattern data for easy Route registration |
APIยถ
- class duck.urls.URLPattern(url: str, handler: Callable, name: Optional[str], methods: List[str], regex: bool = False)[source]ยถ
Bases:
dictA custom dictionary to represent a URL pattern. It allows easy access to URL, handler, name, and methods.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- __repr__()[source]ยถ
Returns a string representation of the URLPattern.
- Returns:
String representation of the URLPattern.
- Return type:
str
- __slots__ยถ
()
- property regexยถ
- duck.urls.path(url: str, view: Callable, name: Optional[str] = None, methods: Optional[List[str]] = None) duck.urls.URLPattern[source]ยถ
Function to easily store urlpattern data for easy Route registration
- duck.urls.re_path(re_url: str, view: Callable, name: Optional[str] = None, methods: Optional[List[str]] = None) duck.urls.URLPattern[source]ยถ
Function to easily store urlpattern data for easy Route registration