Skip to content

Commit

Permalink
chore: maintainable template building with django-cotton and django-t…
Browse files Browse the repository at this point in the history
…ailwind
  • Loading branch information
gbozee committed Aug 20, 2024
1 parent 6bfd394 commit 637eefc
Show file tree
Hide file tree
Showing 20 changed files with 1,713 additions and 8 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ To run the tests, check your test coverage, and generate an HTML coverage report

### Live reloading and Sass CSS compilation

Moved to [Live reloading and SASS compilation](https://cookiecutter-django.readthedocs.io/en/latest/developing-locally.html#sass-compilation-live-reloading).
Moved to [Live reloading and SASS compilation]

Run the following command to develop/style components with live reload

```bash

python manage.py tailwind start

# start the django server in a different shell
python manage.py runserver
```

### Celery

Expand Down
14 changes: 13 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@
"rest_framework.authtoken",
"corsheaders",
"drf_spectacular",
"django_cotton",
'tailwind'
]

LOCAL_APPS = [
"only_django.users",
'theme',
# Your stuff: custom apps go here
]
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
Expand Down Expand Up @@ -178,8 +181,13 @@
# https://docs.djangoproject.com/en/dev/ref/settings/#dirs
"DIRS": [str(APPS_DIR / "templates")],
# https://docs.djangoproject.com/en/dev/ref/settings/#app-dirs
"APP_DIRS": True,
"APP_DIRS": False,
"OPTIONS": {
"loaders": [
"django_cotton.cotton_loader.Loader",
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
# https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
"context_processors": [
"django.template.context_processors.debug",
Expand All @@ -192,6 +200,9 @@
"django.contrib.messages.context_processors.messages",
"only_django.users.context_processors.allauth_settings",
],
"builtins": [
"django_cotton.templatetags.cotton",
],
},
},
]
Expand Down Expand Up @@ -340,3 +351,4 @@
}
# Your stuff...
# ------------------------------------------------------------------------------
TAILWIND_APP_NAME = "theme"
11 changes: 9 additions & 2 deletions config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,22 @@
# WhiteNoise
# ------------------------------------------------------------------------------
# http://whitenoise.evans.io/en/latest/django.html#using-whitenoise-in-development
INSTALLED_APPS = ["whitenoise.runserver_nostatic", *INSTALLED_APPS]
INSTALLED_APPS = [
"whitenoise.runserver_nostatic",
"django_browser_reload",
*INSTALLED_APPS,
]


# django-debug-toolbar
# ------------------------------------------------------------------------------
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#prerequisites
INSTALLED_APPS += ["debug_toolbar"]
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#middleware
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]
MIDDLEWARE += [
"django_browser_reload.middleware.BrowserReloadMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
]
# https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-config
DEBUG_TOOLBAR_CONFIG = {
"DISABLE_PANELS": [
Expand Down
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
kwargs={"exception": Exception("Page not Found")},
),
path("500/", default_views.server_error),
path("__reload__/", include("django_browser_reload.urls")),
]
if "debug_toolbar" in settings.INSTALLED_APPS:
import debug_toolbar
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ services:
- only_django_local_postgres_data_backups:/backups
env_file:
- ./.envs/.local/.postgres
ports:
- "5437:5432"

mailpit:
image: docker.io/axllent/mailpit:latest
Expand All @@ -47,6 +49,8 @@ services:

volumes:
- only_django_local_redis_data:/data
ports:
- "6379:6379"


celeryworker:
Expand Down
3 changes: 2 additions & 1 deletion only_django/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

{% load static i18n %}<!DOCTYPE html>
{% load static i18n tailwind_tags %}<!DOCTYPE html>
{% get_current_language as LANGUAGE_CODE %}
<html lang="{{ LANGUAGE_CODE }}">
<head>
Expand All @@ -16,6 +16,7 @@
<meta name="author"
content="Biola" />
<link rel="icon" href="{% static 'images/favicons/favicon.ico' %}" />
{% tailwind_css %}
{% block css %}
<!-- Latest compiled and minified Bootstrap CSS -->
<link rel="stylesheet"
Expand Down
5 changes: 5 additions & 0 deletions only_django/templates/cotton/card.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="bg-white shadow rounded border p-4">
<h2>{{ title }}</h2>
<p>{{ slot }}</p>
<button href="{{ url }}">Read more for it </button>
</div>
6 changes: 5 additions & 1 deletion only_django/templates/pages/home.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{% extends "base.html" %}


{% block content %}
<c-card title="Hello" url="{% url 'home' %}">
This is a sample card
</c-card>
{% endblock content %}
2 changes: 2 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ djangorestframework==3.15.2 # https://github.com/encode/django-rest-framework
django-cors-headers==4.4.0 # https://github.com/adamchainz/django-cors-headers
# DRF-spectacular for api documentation
drf-spectacular==0.27.2 # https://github.com/tfranzel/drf-spectacular
django-cotton==0.9.26 # https://github.com/django-cotton/django-cotton
django-tailwind[reload]==3.8.0 # https://github.com/django-tailwind/django-tailwind
3 changes: 2 additions & 1 deletion requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Werkzeug[watchdog]==3.0.3 # https://github.com/pallets/werkzeug
ipdb==0.13.13 # https://github.com/gotcha/ipdb
psycopg[c]==3.2.1 # https://github.com/psycopg/psycopg
# psycopg[c]==3.2.1 # https://github.com/psycopg/psycopg
watchfiles==0.21.0 # https://github.com/samuelcolvin/watchfiles

# Testing
Expand Down Expand Up @@ -33,3 +33,4 @@ django-debug-toolbar==4.4.6 # https://github.com/jazzband/django-debug-toolbar
django-extensions==3.2.3 # https://github.com/django-extensions/django-extensions
django-coverage-plugin==3.1.0 # https://github.com/nedbat/django_coverage_plugin
pytest-django==4.8.0 # https://github.com/pytest-dev/pytest-django

3 changes: 2 additions & 1 deletion requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
-r base.txt

gunicorn==23.0.0 # https://github.com/benoitc/gunicorn
psycopg[c]==3.2.1 # https://github.com/psycopg/psycopg
# psycopg[c]==3.2.1 # https://github.com/psycopg/psycopg
psycopg[binary,pool]==3.2.1 # https://github.com/psycopg/psycopg

# Django
# ------------------------------------------------------------------------------
Expand Down
Empty file added theme/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions theme/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ThemeConfig(AppConfig):
name = 'theme'
1 change: 1 addition & 0 deletions theme/static_src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Loading

0 comments on commit 637eefc

Please sign in to comment.