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
  • Наука та технологія

КОМЕНТАРІ • 80

  • @gazm2k5
    @gazm2k5 4 роки тому +4

    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!

  • @lightplan
    @lightplan 2 роки тому +1

    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.

  • @crispr6634
    @crispr6634 3 роки тому

    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!

  • @felipedeabreuprazeres5690
    @felipedeabreuprazeres5690 2 роки тому

    This should be the GoTo link to all those stack overflow static files questions. A good, solid, explanation to the subject. 👍

  • @nielsSavantKing
    @nielsSavantKing Рік тому

    Very clear and at the point explanation. 100K hits. Come on!!

  • @AunZaidi
    @AunZaidi 3 роки тому

    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. 👍🏼👏🏼

  • @relaxworking9756
    @relaxworking9756 2 роки тому

    Thank you sir, this is the best I've seen so far.

  • @smamoden1523
    @smamoden1523 3 роки тому

    best static files explanation on the internet; thank you.

  • @suguruchhaya3194
    @suguruchhaya3194 3 роки тому

    Super easy to understand. #1 video on this topic.

  • @zvonimirvlah9632
    @zvonimirvlah9632 4 роки тому +3

    Finally a great explanation, thanks bro !!

  • @absharif8146
    @absharif8146 3 роки тому

    Lot of confusion solved. Saved life. Love you.

  • @muralidhar40
    @muralidhar40 3 роки тому +1

    ABSOLUTELY FANTASTIC.

  • @jonathantana722
    @jonathantana722 4 роки тому

    Thanks very much for this tutorial is was extremely helpful to me. Deep content, and clear presentation. good job!

  • @rockguy9113
    @rockguy9113 2 роки тому

    Thanks this really saved me after so much frustrations!!!

  • @khatriajaya
    @khatriajaya Рік тому

    Thank you for this video. This is very helpful!!

  • @Lalofike
    @Lalofike 4 роки тому +3

    Thank you man! It was really hard for me to understand this theme in django!

  • @IntoTheUndead
    @IntoTheUndead 3 роки тому

    Hey THANKS a lot man! It really fixed all the queries that i had, THANKS AGAIN

  • @venkataramireddy6689
    @venkataramireddy6689 3 роки тому

    Pretty nice explanation. Keep posting videos on django

  • @prateeksarangi9187
    @prateeksarangi9187 2 роки тому

    Thanks a lot Mate !! Learning in depth

  • @tomaspyth7017
    @tomaspyth7017 4 роки тому

    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

  • @yashmathur1389
    @yashmathur1389 2 роки тому +1

    Really great explanation

  • @Foxygrandpa2131
    @Foxygrandpa2131 4 роки тому

    This is such a great explanation, thank you so much

  • @marcosolis9512
    @marcosolis9512 4 роки тому +1

    Very nice explanation, It is evident you have a really deep understanding of Django. Keep it up, pal.

    • @jaradpython4186
      @jaradpython4186  4 роки тому +3

      I learn it deeply, then forget it like a week later. That's why you gotta document your journey! Make it unique to you.

    • @marcosolis9512
      @marcosolis9512 4 роки тому

      @@jaradpython4186 Same thing happens to me, but I had never thought about that. What a great idea, I will start documentig everything!

  • @jihadhammoud578
    @jihadhammoud578 2 роки тому

    GREAT EXPLANATION PLEASE MORE VIDEOS LIKE THISSSSSSSSSSSSSSSSSSSSSSSSSSSSS

  • @MagnusAnand
    @MagnusAnand 4 роки тому

    great video! Very clear and descriptive

  • @tobiass6584
    @tobiass6584 4 роки тому +2

    Great explanation! Thanks man!

  • @akelius100
    @akelius100 4 роки тому

    Good job dude...Excellent explanation

  • @ysfy5106
    @ysfy5106 Рік тому

    Really good explanation.

  • @hamdan_1242
    @hamdan_1242 Місяць тому

    very detailed Video Brother....

  • @vadymnakonechnyi
    @vadymnakonechnyi 4 роки тому

    Bro, thank you so much for explanation!

  • @namesare4fools
    @namesare4fools 4 роки тому

    u save me there man.. best tutorial ever

  • @user-yw5jc1fi2l
    @user-yw5jc1fi2l 3 роки тому

    This video saved me! Thank you so much.

  • @mmi2805
    @mmi2805 3 роки тому

    Great explanation, thank you very much !!!

  • @utkarshbajpai5035
    @utkarshbajpai5035 3 роки тому

    That was very helpful.

  • @panagiotisgoulas8539
    @panagiotisgoulas8539 3 роки тому

    Thank you helped a lot, honestly docuntation was so bad at this topic.

  • @mdobaidullahal-faruk3457
    @mdobaidullahal-faruk3457 5 років тому +1

    It's really helpful. Thanks a lot.

  • @Cubin4ik
    @Cubin4ik 3 роки тому

    Great explanation!

  • @bruhhhhh718
    @bruhhhhh718 3 роки тому

    solid man, thank you

  • @jaecheokkim99
    @jaecheokkim99 4 роки тому

    Thank you so much for your great explanation! Thanks. really.

  • @Chespiritoish
    @Chespiritoish 3 роки тому

    Amazing you help me to solve my problem!!! :D

  • @ShaidaMuhammad
    @ShaidaMuhammad 3 роки тому

    Thanks man. It helped.

  • @ellsonmendesYT
    @ellsonmendesYT 3 роки тому

    Now it is clear, thanks

  • @ekbergpeter6987
    @ekbergpeter6987 4 роки тому

    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?

  • @priyamvashi2187
    @priyamvashi2187 3 роки тому

    Great video

  • @esrefhyd-amp1036
    @esrefhyd-amp1036 4 роки тому +1

    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

  • @liviumircea6905
    @liviumircea6905 2 роки тому

    Excellent !

  • @rajyalakshmid
    @rajyalakshmid 3 роки тому

    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?

  • @melaniecourtois3231
    @melaniecourtois3231 4 роки тому +2

    Great video! Thanks!!

  • @numanali8545
    @numanali8545 3 роки тому

    Can't be better...omg...thx

  • @yoga_with_atharva
    @yoga_with_atharva 4 роки тому

    really helpful , thank you

  • @HydoSkills
    @HydoSkills 2 роки тому

    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.

  • @bigsneeks5714
    @bigsneeks5714 4 роки тому

    getting this error "ModuleNotFoundError: No module named 'puppies'"
    **sigh

  • @fabisierra7655
    @fabisierra7655 3 роки тому

    it´s the same for a three.js project?

  • @glassy5716
    @glassy5716 3 роки тому

    Thank you so much

  • @amannegi8256
    @amannegi8256 3 роки тому

    wowwww all clear

  • @drustan6890
    @drustan6890 4 роки тому

    can you do a video on media root for images?

  • @vijay1338
    @vijay1338 Рік тому

    Thank you soo much

  • @kumaranuj6548
    @kumaranuj6548 3 роки тому

    god bless you ! better explation then stackoverflow

  • @shynggyskassen942
    @shynggyskassen942 3 роки тому

    Thank you so much!!!

  • @hammadyasir2174
    @hammadyasir2174 2 роки тому

    Thanks a lot.

  • @dgiri2333
    @dgiri2333 2 роки тому

    Can you do one video for django and nginx

  • @justalazyseo8285
    @justalazyseo8285 2 роки тому

    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.

  • @amirmasoud1192
    @amirmasoud1192 4 роки тому

    Thank you

  • @omarkelalech7187
    @omarkelalech7187 3 роки тому

    thank you

  • @mamamat223
    @mamamat223 3 роки тому

    thank you.

  • @nhanNguyen-wo8fy
    @nhanNguyen-wo8fy 2 роки тому

    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

  • @chawza8402
    @chawza8402 4 роки тому

    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

  • @4kids555
    @4kids555 Рік тому

    thanks g

  • @naheliegend5222
    @naheliegend5222 3 роки тому

    I still do not understand that STATIC_ROOT thing...

  • @anonymouswanted3686
    @anonymouswanted3686 2 роки тому

    why is keanu reaves sitting here

  • @fanfarorro
    @fanfarorro 4 роки тому

    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)

    • @marcosolis9512
      @marcosolis9512 4 роки тому

      Is your DEBUF flag set to true in the settings file?

    • @fanfarorro
      @fanfarorro 4 роки тому

      @@marcosolis9512 yes

    • @marcosolis9512
      @marcosolis9512 4 роки тому +1

      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

    • @seanosuilleabhainemerald
      @seanosuilleabhainemerald 3 роки тому

      So helpful thank you.

  • @mukeshvij2935
    @mukeshvij2935 3 роки тому

    I can't understand but thanks