This page provides an overview of the basics of using the `'wagtail.documents'` app in your Wagtail project.
## Including `'wagtail.documents'` in `INSTALLED_APPS`
To use the `wagtail.documents` app, you need to include it in the `INSTALLED_APPS` list in your Django project's settings. Simply add it to the list like this:
```python
# settings.py
INSTALLED_APPS = [
# ...
'wagtail.documents',
# ...
]
```
## Setting up URLs
Next, you need to set up URLs for the `wagtail.documents` app. You can include these URLs in your project's main urls.py file. To do this, add the following lines:
```python
# urls.py
from wagtail.documents import urls as wagtaildocs_urls
urlpatterns = [
# ...
path('documents/', include(wagtaildocs_urls)),
# ...
]
```
New documents saved are stored in the [reference index](managing_the_reference_index) by default.
Links to documents can be made in pages using the [`RichTextField`](rich_text_field). By default, Wagtail will include the features for adding links to documents see [](rich_text_features).
You can either exclude or include these by passing the `features` to your `RichTextField`. In the example below we create a `RichTextField` with only documents and basic formatting.
`StreamField` provides a content editing model suitable for pages that do not follow a fixed structure. To add links to documents using `StreamField`, include it in your models and also include the `DocumentChooserBlock`.
Create a `Page` model with a `StreamField` named `doc` and a `DocumentChooserBlock` named `doc_link` inside the field:
```python
# models.py
from wagtail.fields import StreamField
from wagtail.documents.blocks import DocumentChooserBlock
class BlogPage(Page):
# ... other fields
documents = StreamField([
('document', DocumentChooserBlock())
],
null=True,
blank=True,
use_json_field=True,
)
panels = [
# ... other panels
FieldPanel("documents"),
]
```
In `blog_page.html`, add the following block of code to display the document link in the page:
Documents in Wagtail can be organized within [collections](https://docs.wagtail.org/en/v4.0/editor_manual/documents_images_snippets/collections.html). Collections provide a way to group related documents. You can cross-link documents between collections and make them accessible through different parts of your site.
If you want to restrict access to certain documents, you can place them in [private collections](https://guide.wagtail.org/en-latest/how-to-guides/manage-collections/#privacy-settings).
Private collections are not publicly accessible, and their contents are only available to users with the appropriate permissions.
## API access
Documents in Wagtail can be accessed through the API via the `wagtail.documents.api.v2.views.DocumentsAPIViewSet`. This allows you to programmatically interact with documents, retrieve their details, and perform various operations.
For more details, you can refer to the [API section](api_v2_configure_endpoints) that provides additional information and usage examples.