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