Skip to content

It's an example of how django can work with tailwind as a plants online shop

Notifications You must be signed in to change notification settings

Benfoxyy/Django-Tailwind-Setup

Repository files navigation

Django Tailwind Setup

This is an document about how to connect django to tailwind

python django sqlite javascript jquery html5 css3 tailwind

Demo








Guideline

Collabration

This project is collabration between me as BackEnd and Sharafi as FrontEnd developer

Tailwind Setup

First Step

In the begining you need to setup your django project

Requirements

Node

Ensure that node js is installed on your computer by running this command :

node -v

Npm

The reason of node is for npm pakage so ensure that it's installed by node :

npm -v

Django-Tailwind Package

Installing

let's start whith installing django-tailwind , It's pakage for connect django and tailwind :

python -m pip install django-tailwind

Setting

Add 'tailwind' to INSTALLED_APPS in settings.py :

INSTALLED_APPS = [
  # other Django apps
  'tailwind',
]

Tailwind Initialising

Create a Tailwind CSS compatible Django app, I like to call it theme :

python manage.py tailwind init

New App

Add your newly created 'theme' app to INSTALLED_APPS in settings.py :

INSTALLED_APPS = [
  # other Django apps
  'tailwind',
  'theme'
]

Register Tailwind App

Register the generated 'theme' app by adding the following line to settings.py file :

TAILWIND_APP_NAME = 'theme'

INTERNAL_IPS

Make sure that the INTERNAL_IPS list is present in the settings.py file and contains the 127.0.0.1 ip address :

INTERNAL_IPS = [
    "127.0.0.1",
]

Last Prepration

Install Tailwind CSS dependencies, by running the following command :

python manage.py tailwind install

Usage

Option

The Django Tailwind comes with a simple base.html template located at your_tailwind_app_name/templates/base.html . You can always extend or delete it if you already have a layout .

If you are not using the base.html template that comes with Django Tailwind, add {% tailwind_css %} to the base.html template :

{% load static tailwind_tags %}
...
<head>
   ...
   {% tailwind_css %}
   ...
</head>

The {% tailwind_css %} tag includes Tailwind’s stylesheet .

Django_Browser_Reload

Let’s also add and configure django_browser_reload , which takes care of automatic page and css refreshes in the development mode . Add it to INSTALLED_APPS in settings.py :

INSTALLED_APPS = [
  # other Django apps
  'tailwind',
  'theme',
  'django_browser_reload'
]

Staying in settings.py , add the middleware:

MIDDLEWARE = [
  # ...
  "django_browser_reload.middleware.BrowserReloadMiddleware",
  # ...
]

The middleware should be listed after any that encode the response, such as Django’s GZipMiddleware . The middleware automatically inserts the required script tag on HTML responses before </body> when DEBUG is True .

Include django_browser_reload URL in your root url.py :

from django.urls import include, path
urlpatterns = [
    ...,
    path("__reload__/", include("django_browser_reload.urls")),
]

Start Project

Run your django :

python manage.py runserver

Finally, you should be able to use Tailwind CSS classes in HTML. Start the development server by running the following command in your terminal :

python manage.py tailwind start

Thanks For Visiting

I hope that you enjoy it, Let me know if you have any suggestion

About

It's an example of how django can work with tailwind as a plants online shop

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published