Giter Site home page Giter Site logo

mattkevan / django-htmx Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 27.3 MB

Django starter project with Tailwind & HTMX

Home Page: https://www.kevan.tv/projects/django-htmx-tailwind/

License: Other

Python 22.59% CSS 3.00% HTML 70.91% JavaScript 3.50%
django htmx python tailwindcss

django-htmx's Introduction

A Django starter project with Tailwind, Alpine.js and HTMX. Based on DjangoX by Will Vincent.

New features

  • Styling with Tailwind.
  • Interactivity with Alpine.js.
  • Modern front-end experience via HTMX.
  • Environment variables with python-dotenv.
  • Media file support via Cloudinary.

DjangoX features

Getting started

Follow the installation instructions below, then follow these steps to configure the extra bits.

Environments

Create a .env file in your project root and add your secret key and debug settings.

Tailwind

Forms are styled with crispy-tailwind, but it doesn't support dark mode so I've had to override a bunch of templates. These are in templates/tailwind.

Development mode

python manage.py tailwind start

To run tailwind in development mode. This will watch for changes and use browsersync to auto-reload the browser.

Production mode

python manage.py tailwind build

This will create a build optimised for production.

HTMX

Browsing between pages

Add the following code to your a tags:

 hx-get="{% url 'home' %}" hx-target="body" hx-push-url="true" hx-indicator=".progress"
  • hx-get="{% url 'home' %} - The target page if a link, should be the same as the href
  • hx-target="body" – The element to switch out content from. Can be set to any element, but body is useful for switching between pages.
  • hx-push-url="true" – Adds the link to the browser history/back button.
  • hx-indicator=".progress" – Shows the progress indicator at the top of the page when loading.

Cloudinary

Uncomment the Cloudinary config in settings.py and add your cloud name, API key and secret to your environment variables.

Import Cloudinary in models.py:

from cloudinary.models import CloudinaryField
from cloudinary.uploader import upload

Add Cloudinary fields to your model:

image = CloudinaryField('image')

DjangoX

A batteries-included Django starter project. To learn more try the books Django for Beginners, Django for APIs, and Django for Professionals.

🚀 Features


Table of Contents


📖 Installation

DjangoX can be installed via Pip or Docker. To start, clone the repo to your local computer and change into the proper directory.

$ git clone https://github.com/MattKevan/djangox-tailwind.git
$ cd djangox-tailwind

Pip

$ python -m venv .venv

# Windows
$ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
$ .venv\Scripts\Activate.ps1

# macOS
$ source .venv/bin/activate

(.venv) $ pip install -r requirements.txt
(.venv) $ python manage.py migrate
(.venv) $ python manage.py createsuperuser
(.venv) $ python manage.py runserver
# Load the site at http://127.0.0.1:8000

Docker

To use Docker with PostgreSQL as the database update the DATABASES section of django_project/settings.py to reflect the following:

# django_project/settings.py
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "postgres",
        "USER": "postgres",
        "PASSWORD": "postgres",
        "HOST": "db",  # set in docker-compose.yml
        "PORT": 5432,  # default postgres port
    }
}

The INTERNAL_IPS configuration in django_project/settings.py must be also be updated:

# config/settings.py
# django-debug-toolbar
import socket
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[:-1] + "1" for ip in ips]

And then proceed to build the Docker image, run the container, and execute the standard commands within Docker.

$ docker-compose up -d --build
$ docker-compose exec web python manage.py migrate
$ docker-compose exec web python manage.py createsuperuser
# Load the site at http://127.0.0.1:8000

Next Steps

I cover all of these steps in my three books: Django for Beginners, Django for APIs, and Django for Professionals.


🤝 Contributing

Contributions, issues and feature requests are welcome! See CONTRIBUTING.md.

⭐️ Support

Give a ⭐️ if this project helped you!

License

The MIT License

django-htmx's People

Contributors

49e94b8f256530dc0d41f740dfe8a4c1 avatar afarntrog avatar barnwell avatar bebehr avatar flourish90 avatar mattkevan avatar mspirbhai avatar pquentin avatar rahmanfadhil avatar smithdc1 avatar vineetpandey avatar warkinstar avatar wsvincent avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.