mirror of
https://github.com/django-components/django-components.git
synced 2025-08-04 14:28:18 +00:00
docs: mention URL auto-gen in README (#1099)
This commit is contained in:
parent
9f9b1f7232
commit
1dfec8fc6d
2 changed files with 20 additions and 4 deletions
|
@ -243,12 +243,17 @@ Read more about [HTML attributes](../../concepts/fundamentals/html_attributes/).
|
|||
|
||||
- Expose components as views with `get`, `post`, `put`, `patch`, `delete` methods
|
||||
|
||||
- Automatically create an endpoint for the component with `Component.Url.public`
|
||||
|
||||
```py
|
||||
# components/calendar/calendar.py
|
||||
@register("calendar")
|
||||
class Calendar(Component):
|
||||
template_file = "calendar.html"
|
||||
|
||||
class Url:
|
||||
public = True
|
||||
|
||||
class View:
|
||||
def get(self, request, *args, **kwargs):
|
||||
page = request.GET.get("page", 1)
|
||||
|
@ -264,8 +269,11 @@ class Calendar(Component):
|
|||
"page": page,
|
||||
}
|
||||
|
||||
# urls.py
|
||||
path("calendar/", Calendar.as_view()),
|
||||
# Get auto-generated URL for the component
|
||||
url = get_component_url(Calendar)
|
||||
|
||||
# Or define explicit URL in urls.py
|
||||
path("calendar/", Calendar.as_view())
|
||||
```
|
||||
|
||||
### Type hints
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue