docs: mention URL auto-gen in README (#1099)

This commit is contained in:
Juro Oravec 2025-04-07 19:26:50 +02:00 committed by GitHub
parent 9f9b1f7232
commit 1dfec8fc6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View file

@ -253,12 +253,17 @@ Read more about [HTML attributes](https://django-components.github.io/django-com
- Expose components as views with `get`, `post`, `put`, `patch`, `delete` methods - Expose components as views with `get`, `post`, `put`, `patch`, `delete` methods
- Automatically create an endpoint for the component with `Component.Url.public`
```py ```py
# components/calendar/calendar.py # components/calendar/calendar.py
@register("calendar") @register("calendar")
class Calendar(Component): class Calendar(Component):
template_file = "calendar.html" template_file = "calendar.html"
class Url:
public = True
class View: class View:
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
page = request.GET.get("page", 1) page = request.GET.get("page", 1)
@ -274,8 +279,11 @@ class Calendar(Component):
"page": page, "page": page,
} }
# urls.py # Get auto-generated URL for the component
path("calendar/", Calendar.as_view()), url = get_component_url(Calendar)
# Or define explicit URL in urls.py
path("calendar/", Calendar.as_view())
``` ```
### Type hints ### Type hints

View file

@ -243,12 +243,17 @@ Read more about [HTML attributes](../../concepts/fundamentals/html_attributes/).
- Expose components as views with `get`, `post`, `put`, `patch`, `delete` methods - Expose components as views with `get`, `post`, `put`, `patch`, `delete` methods
- Automatically create an endpoint for the component with `Component.Url.public`
```py ```py
# components/calendar/calendar.py # components/calendar/calendar.py
@register("calendar") @register("calendar")
class Calendar(Component): class Calendar(Component):
template_file = "calendar.html" template_file = "calendar.html"
class Url:
public = True
class View: class View:
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
page = request.GET.get("page", 1) page = request.GET.get("page", 1)
@ -264,8 +269,11 @@ class Calendar(Component):
"page": page, "page": page,
} }
# urls.py # Get auto-generated URL for the component
path("calendar/", Calendar.as_view()), url = get_component_url(Calendar)
# Or define explicit URL in urls.py
path("calendar/", Calendar.as_view())
``` ```
### Type hints ### Type hints