Run the following command:
pip install django-cotton
Then update your settings.py:
INSTALLED_APPS = [
'django_cotton',
]
This will automatically handle the settings.py adding the required loader and templatetags.
If your project requires any non-default loaders or you do not wish Cotton to manage your settings, you should instead provide `django_cotton.apps.SimpleAppConfig` in your INSTALLED_APPS:
INSTALLED_APPS = [
'django_cotton.apps.SimpleAppConfig',
]
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
...
"OPTIONS": {
"loaders": [(
"django.template.loaders.cached.Loader",
[
"django_cotton.cotton_loader.Loader",
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
)],
"builtins": [
"django_cotton.templatetags.cotton"
],
}
}
]
Create a new directory in your templates directory called cotton. Inside this directory create a new file called card.html with the following content:
<div class="bg-white shadow rounded border p-4">
<h2>{{ title }}</h2>
<p>{{ slot }}</p>
<button href="{% url url %}">Read more</button>
</div>
def dashboard_view(request):
return render(request, "dashboard.html")
<c-card title="Trees" url="trees">
We have the best trees
</c-card>
<c-card title="Spades" url="spades">
The best spades in the land
</c-card>
We have the best trees
The best spades in the land
Cotton uses the following naming conventions:
<c-my-component />
<c-sidebar.menu.link />
<c-my-component />
or have a closing tag <c-my-component></c-my-component>