Understanding Django Static Files
Вставка
- Опубліковано 21 лип 2024
- Django static files can be confusing to setup - especially if you're a beginner. The word "static" sounds mysterious, convoluted and like jargon. I guess there's not one-word to describe CSS, Javascript and Images... so they chose "static" files.
Anyways, even if you've setup Django static files in the past, just REMEMBERING what STATIC_URL, STATICFILES_DIRS and STATIC_ROOT can be difficult if some time has passed and you aren't knee-deep in Django projects all the time.
For these reasons, I wanted to make this video explaining my CURRENT understand (as of 5/30/2019) of Django static files. Use this video as a reference the next time you need to setup static files in Django.
In this Django tutorial, I will first discuss what Django static files, what the staticfiles app is, and what the settings.py variables mean and do.
For example, it's not obvious that "STATIC_URL" is simply a URL prefix for the "STATIC_ROOT" and it's easy to be confused when you hear the words "STATIC_URL" and "STATIC_ROOT" - not intuitive unless you actually know what these do!
Furthermore, when you go to setup static files locally in your Django project, you will likely find it piecemeal - some from the Django documentation, some from StackOverflow and some from UA-cam videos.
That's why I wanted a single video to really show what everything means and how to setup Django local static files!
If anything I said in this video is misleading or inaccurate, please do bring it up. I welcome the feedback. I always learn more when I make a mistake than I do when I don't.
So if you're ready to understand Django static files, watch this video all the way through so you see the static files example and walkthrough at the end.
Helpful links:
- docs.djangoproject.com/en/2.2...
- docs.djangoproject.com/en/2.2...
- stackoverflow.com/questions/1...
#Python #Django #StaticFiles - Наука та технологія
That was solid. I've done a couple of django tutorials and they explain how to use static files but not how it's all working under the hood, so when stuff goes wrong it's really hard to fix. This explanation gave me a much better understanding. Thanks!
Thank you very much! I've noticed that this is the only tutorial that properly explains how Static files work in Django. Most tutorials seem to ignore some of the basic concepts.
This is the best django related tutorial I've come across. Instead of just showing how to use a feature, you go into how the feature actually works. Great content!
This should be the GoTo link to all those stack overflow static files questions. A good, solid, explanation to the subject. 👍
Very clear and at the point explanation. 100K hits. Come on!!
I see you don't post videos anymore but brother I found this very useful. I am new developer and new to Django and being explained one concept in such detail was genuinely helpful. Thank you and you did a great job. 👍🏼👏🏼
Thank you sir, this is the best I've seen so far.
best static files explanation on the internet; thank you.
Super easy to understand. #1 video on this topic.
Finally a great explanation, thanks bro !!
Lot of confusion solved. Saved life. Love you.
ABSOLUTELY FANTASTIC.
Thanks very much for this tutorial is was extremely helpful to me. Deep content, and clear presentation. good job!
Thanks this really saved me after so much frustrations!!!
Thank you for this video. This is very helpful!!
Thank you man! It was really hard for me to understand this theme in django!
Hey THANKS a lot man! It really fixed all the queries that i had, THANKS AGAIN
Pretty nice explanation. Keep posting videos on django
Thanks a lot Mate !! Learning in depth
thanks a lot for sharing your knowledge. bevor i saw your video i really couldn't figure out how this static thing work since i am new to django and i don't even know how to use the documentation effectively (looks overloaded for me). so thanks again. great work thumbs up
Really great explanation
This is such a great explanation, thank you so much
Very nice explanation, It is evident you have a really deep understanding of Django. Keep it up, pal.
I learn it deeply, then forget it like a week later. That's why you gotta document your journey! Make it unique to you.
@@jaradpython4186 Same thing happens to me, but I had never thought about that. What a great idea, I will start documentig everything!
GREAT EXPLANATION PLEASE MORE VIDEOS LIKE THISSSSSSSSSSSSSSSSSSSSSSSSSSSSS
great video! Very clear and descriptive
Great explanation! Thanks man!
Good job dude...Excellent explanation
Really good explanation.
very detailed Video Brother....
Bro, thank you so much for explanation!
u save me there man.. best tutorial ever
This video saved me! Thank you so much.
Great explanation, thank you very much !!!
That was very helpful.
Thank you helped a lot, honestly docuntation was so bad at this topic.
It's really helpful. Thanks a lot.
Great explanation!
solid man, thank you
Thank you so much for your great explanation! Thanks. really.
Amazing you help me to solve my problem!!! :D
Thanks man. It helped.
Now it is clear, thanks
Thanks for the video. One question. After you changed the root and ran the command for collecting static files, is it possible to change it again? If so, how? And is it possible on a server to have a directory outside the base so it's not accessible by browsing to that image? Will they still be available for my templates?
Great video
Hi bro,I am using Google chats ,when calling chats JavaScript , script it's return fine, JavaScript depending other scripts are losing path from after url pattern ,how to resolve
Excellent !
Thank you for the detailed explanation. I am having an issue with static files serving in my server. I am able to run to serve static files all the css working as expected . But the same code whihch deployed using the docker is not serving the static files. all the files available in server.ANy clue?
Great video! Thanks!!
You bet!
Can't be better...omg...thx
really helpful , thank you
Okay so for every one reading this searching the same thing I do which is not the stuff this guys explaining. You want to make urls inside css file static. Yes that's what I want too. For example linking css files with @import: url([static path]); .. I'm sorry to inform you there's no easy fix without a compressor. And next to the compressor you need to use sass django-libsass. Then setup the compressor as shown in GitHub, then setup the libsass also shown in GitHub. I know this is a terrible way of serving css and other linking scripts since there's no real none static way of doing it but this is the only way to achieve it. In a complex design this might require you to edit hundreds if not thousands of lines of code to make it work. Therefor I ditched django... again for the same reason i did a couple of years back, this system of serving static files is the weakest part of the framework. So if you have a complex design where you need the use of urls in static css files: yes there is a way, no your not gonna like it.
getting this error "ModuleNotFoundError: No module named 'puppies'"
**sigh
it´s the same for a three.js project?
Thank you so much
wowwww all clear
can you do a video on media root for images?
Thank you soo much
god bless you ! better explation then stackoverflow
Thank you so much!!!
Thanks a lot.
Can you do one video for django and nginx
This was great! Would love to see even more in-depth material about this!
I found an easy way to test if staticfiles work or not: Install gunicorn and run gunicorn yourapp.wsgi. If the static files are not collected and configured correctly, they will not show. Benefit of this is that gunicorn can't deal with djangos dev env static.
Thank you
thank you
thank you.
4:55 giải thích static_url
6:40 -- 14:20 giải thích staticfiles_dirs trong setting
15:40 explain static_root
22:30
I have read the documentation numerous times but still don't understand how Django handles static files
funny thing what you did is walkthrough the same doc and yet it is clearer
thanks g
I still do not understand that STATIC_ROOT thing...
why is keanu reaves sitting here
My django is crazy. STATIC_URL = 'assets'
then in folder /APP/static/APP/img/img.jpg etc.
the path to img in html: assets/app/img/img.jpg
why is this working x)
Is your DEBUF flag set to true in the settings file?
@@marcosolis9512 yes
I just realized you dont have a leading and trailing "/" in your STATIC_URL. It should be like this: "/assets/"
The docs explicitly say the slash is needed:
docs.djangoproject.com/en/3.0/ref/settings/#static-url
So helpful thank you.
I can't understand but thanks