#๐Ÿ”’ Tailwind is v4 is not working on Django

168 messages ยท Page 1 of 1 (latest)

fallen rover
#

I have properly configured but can't figure out why tailwind is not properly running on at home.html

//demo/mysite/setting.py

STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'static'
STATICFILES_DIRS = ['mysite/static']

# Media Files configuration
MEDIA_URL  = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'

output.css has values but it seems to not compile new classes.

//demo/templates/home.html

<section class="flex items-center justify-center mt-10">
    <div class="w-full max-w-2xl shadow-md rounded-lg overflow-hidden">
        <table class="w-full text-sm text-left text-gray-700">
            <thead class="text-xs text-red-500 uppercase bg-green-700">
                <tr>
                    <th scope="col" class="px-6 py-3">#</th>
                    <th scope="col" class="px-6 py-3">First</th>
                    <th scope="col" class="px-6 py-3">Last</th>
                    <th scope="col" class="px-6 py-3">Handle</th>
                </tr>
            </thead>
            <tbody>
                <tr class="bg-white border-b hover:bg-green-50 transition-colors">
                    <th scope="row" class="px-6 py-4 font-medium text-gray-900">3</th>
                    <td class="px-6 py-4">Larry</td>
                    <td class="px-6 py-4">the Bird</td>
                    <td class="px-6 py-4 text-green-600 font-medium">@twitter</td>
                </tr>
            </tbody>
        </table>
    </div>
</section>
coral lindenBOT
#

@fallen rover

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

winter raven
#

'python page'????

winter raven
fallen rover
#

Sorry what should be the title

winter raven
#

what web development framework are you using??

fallen rover
#

django

#

Tailwind is v4 is not working on Django

winter raven
#

try

fallen rover
#

STATIC_URL = 'static/' this one?

winter raven
#
STATIC_URL = '/static/'
#

can you also share the backend?

fallen rover
#

I can give you the repo if u want

#

Not sure if this is the backend you are requesting.

/urls.py

from django.contrib import admin
from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
#
/views.py
def home(request):
    employees = Employee.objects.all()
    context = {
        'employees': employees
    }
    return render(request, 'home.html', context)
#

It has something to do with tailwind not properly compiling the new classes

#

the output.css always shows the same value

#

Even if I change the bg of the table or section

fallen rover
boreal fjord
fallen rover
#

yessir

boreal fjord
#

Or hard refreshing the page?

#

CTRL + SHIFT + R?

fallen rover
#

Yes just did it

#

still same output

#

Am I missing some configurations ?

#

based on the repo

boreal fjord
fallen rover
#

yes

boreal fjord
#

I see no tailwind css as part of the link

coral lindenBOT
#

templates/home.html line 9

<link rel="stylesheet" href="{% static 'css/output.css' %}">```
winter raven
#

maybe tailwind was on the out.css...

winter raven
fallen rover
#

The output.css

#

This is what it looks like

#

its tailwind generated

boreal fjord
#

hmmm

fallen rover
#

for sure I am missing the @import tailwindcss

#

but donno what to do with it

#

have you guys integrated tailwind in django?

winter raven
#

@fallen rover can you open the devtools on your browser??

fallen rover
#

sure

winter raven
fallen rover
#

but thats cdn

winter raven
fallen rover
#

oaky

#

what should i type

winter raven
#

Wait that's not chrome.....

fallen rover
#

its chrome

#

just on macos

boreal fjord
#

And what does your Django terminal show?

fallen rover
winter raven
fallen rover
winter raven
#

Looks fine

fallen rover
#

do you guys use this command npx @tailwindcss/cli -i ./static/src/input.css -o ./static/dist/output.css --watch or you just do npm run watch?

winter raven
boreal fjord
#

I don't use npm directly into django templates

fallen rover
winter raven
#

Then click, and show the devtools

boreal fjord
winter raven
#

I prefer a copy of the tailwind on the project directory

boreal fjord
# fallen rover

Its possible that you have another django instance running. What happens if you stop your django runserver, and reload this page?

fallen rover
winter raven
#

You didn't click...

fallen rover
fallen rover
winter raven
#

it looks fine... Maybe your mistakenly used different css class

fallen rover
#

and also npm run watch

winter raven
#

It's displaying whatever those class you add to those elements

fallen rover
#

It's okay I will try to figure this out and post my solution if I get it correctly

boreal fjord
fallen rover
winter raven
fallen rover
#

for some reason it show "This site cant be reached" Then reloads itself

#

and display the page

#

weird

winter raven
#

well because you shutdown the server ..

#

It's maybe loading what's ever on the cache

winter raven
#

So theres no issues here

fallen rover
#

I was following some tutorials on youtube but was using bootstrap instead of tw

winter raven
#

it simply lacks styles

fallen rover
#

thats why I tried installed tw myself

#

didnt realized it was harder than i thought

winter raven
#

idk how to use tailwind.... I just write the css code manually.....

fallen rover
#

wow we got a badass over here

winter raven
#

not really.... That's how everyone do it

#

Right..??

boreal fjord
#

If I load the output.css manually and removing the Django templating from home.html, it does apply the styles

fallen rover
#

I will try

boreal fjord
#

something is not right with the django templating system in your project

winter raven
#

what {{ load static }} do on Django??

boreal fjord
winter raven
#

on flask I doesn't have to do that ._.

#

I thought it would be same as flask templates

boreal fjord
#

I can sorta see why... the views.py is in the mysite folder instead of the employees

boreal fjord
winter raven
#

Fair

fallen rover
boreal fjord
boreal fjord
fallen rover
#

Im new to python and django and trying to learn here

boreal fjord
fallen rover
#

Question what does this error mean

#

can't resolve 'tailwindcss' ...

boreal fjord
#
- npx @tailwindcss/cli
+ npx tailwindcss
fallen rover
boreal fjord
#

@fallen rover I figured it out...

fallen rover
boreal fjord
coral lindenBOT
#

mysite/settings.py lines 118 to 120

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'static'
STATICFILES_DIRS = ['mysite/static']```
boreal fjord
#

and in your project, you have 2 static folders

#

one outside of the mysite

#

and the other inside the mysite folder

winter raven
#

how can you have 2 folder with same name...

boreal fjord
#

Its been loading the static css file inside the mysite and not the outside

boreal fjord
fallen rover
#

should I remove the on inside mysite?

winter raven
#

theres no reason to have morethan 1 static folder

boreal fjord
fallen rover
#

what should this looklike

#

STATICFILES_DIRS = ['mysite/static']

#

just mysite?

#

I removed the static folder inside the mysite

boreal fjord
#

if you're only referencing to the the static folder outside of mysite, make the STATICFILES_DIRS an empty list (or just remove it entirely)

#

Because you have it defined in STATIC_ROOT already

fallen rover
#

what's the right way of calling the django image?

boreal fjord
#

The value of your current STATIC_ROOT should be in STATICFILES_DIRS

#

Your STATIC_ROOT should just be a folder name like 'staticfiles'

fallen rover
#

interesting result

boreal fjord
#

Thats from your output.css

#

idk how you generated your tailwind css but those are the colors you picked

#

not shaming you for your choice of colors but it is what it is

fallen rover
#

The tailwind thing is still not working btw

boreal fjord
#

oh you mean the npx thingy? no clue. Ask in a Tailwind server

fallen rover
#

what is django using as it frontend engine?

#

like forexample in laravel it's using blade

boreal fjord
#

Django uses its own templating system.

#

aka Django templates

#

You can however, not use Django templates and use whatever frontend you want. Just use Django together with an API middleware like Django REST Framework (aka DRF) or Django-Ninja

#

Then pass the API endpoints to whatever frontend of choice you want like Flutter, React Native, Svelte, etc

fallen rover
#

so django and spa is notrecommended

boreal fjord
#

I'm pretty sure you can do Django and SPA, just not in the same server/instance

fallen rover
#

okay got it ๐Ÿ™‚

#

i just realized my nodemodule folder is inside the project mysite

#

which is wrong lol

boreal fjord
#

Be sure to add nodemodule into your .gitignore next time ๐Ÿ™‚

coral lindenBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.