Try Django 1.8 Tutorial - 18 of 42 - Serving Static Files - Learn Django

preview_player
Показать описание
Try Django 1.8 Tutorial - 18 of 42 - Serving Static Files - Learn Django

Topics include:
- Django Project Setup
- Models, Model Forms, Forms, Form Validation
- Function Based Views
- Integrate Bootstrap front-end framework.
- Django Registration Redux for Authentication/Registration
- Launch on a live server
- And More

Post any/all questions in the comments area -- we try to answer all. If you know the answer someone else's question(s), please share!

We are Coding For Entrepreneurs [CFE] and have built an entire library of content to help you master Django and other web technologies launch real projects faster. Enroll today for as low as $20/month.

What Technology you'll learn in the Try Django 1.8 series:
-- Bootstrap (version 3.3): a powerful front-end framework used by thousands of sites around the world. Bootstrap makes it easier to have a responsive web application so it looks awesome on any mobile device and any desktop computer.

All of our tutorials have a simple goal in mind: get you building something real and quickly.

Рекомендации по теме
Комментарии
Автор

I discovered my static files serve only after changing the STATIC_URL = '/staticabc/' but if i take it back to default it results blank web page. what could be the reason?

ikechukwuorji
Автор

Subscribed! Just solved my problem Ive been having for a while! Aka trying out photologue; the uploaded pictures havent been loading from MEDIA_ROOT in development environment, tried multiple approaches, read lots of docs and still missed this simple solution!

Aikko
Автор

Could you clarify the issue of those urlpatterns += static(settings.STATIC_URL,
urlpatterns += static(settings.MEDIA_URL,


We can see:

If you use django.contrib.staticfiles <...>, runserver will do this automatically when DEBUG is set to True. If you don’t have django.contrib.staticfiles in INSTALLED_APPS, you can still manually serve static files using the view.

If I'm not mistaken, we really use django.contrib.staticfiles. I have slowed the speed down to 0.25 and
at about 4:20 I can see django.contrib.staticfiles in the installed apps in your screen.


Could you clarify: if we already use django.contrib.staticfiles, why should we use those urlpatterns += static()?

TheKifsif
Автор

I don't understand why you go to all the trouble to set up complicated STATIC_ROOT and STATICFILE_DIRS (across two videos) when you can just create a directory called "static" and it will get automatically detected by default. It seems to be making something that should be dead simple into something ridiculously complex.

px
Автор

i apreciate you free tutorials but you need to be more objetive, its kinda abstract

nashvilla
Автор

OK
i am confused in this vid
my understanding:
SERVING is for production so that static files would be obtained from path mentioned in static_root.... had it been in development, static files would have been auto detected via django.conf.staticfiles
correct me if i am wrong!

MrLilgangsta
Автор

Hi Great tutorials but I need really help. I have an issues on admin link getting this error
Invalid block tag: 'static_in_pro', expected 'endblock'
Can you help me with this issue please. Thanks.

elijahlinoge
Автор

Great Tutorial~And I'm still a little bit confused about where the risk of "expose static file root folders" to production env. come from?Will it be more hackable?

nickwong-pg
Автор

Dude, sincerely, you have awesome videos and you have a new paid suscriber in CFE website. lol, amazing dude. I'm your fan.

ManuJimenez
Автор

I have one question: I need to run all this configurantion process for every project? Is there a way to keep that like a "basic project already configured"?

_kaio_
Автор

I'm receiving this error

ImproperlyConfigured at /
Empty static prefix not permitted

Shyamsaini
Автор

For development server, is modifying the urls.py necessary? Because I haven't done so and my static files are being rendered.

dfhfdgfgdfshdfhe
Автор

what do u mean "you dont want to do this in production, only in development"? how would you do it in production??

gabrield
Автор

i meet a problem: If set, MEDIA_URL must end with a slash, i am pycharm and cmd!why?

mingyang
Автор

I would really appreciate if it had been slower, i'm lost in this STATIC thing..

ruthvikvijayakumar
Автор

Hey Justin!
Your videos are just great!
My projects is built around a python script, quite complex to ctrl-c ctrl-v to js because why not. The question is can I run python scripts in django, print them and bring them alive in this environment? can a button call a function and the return of it being printed or added to the database?

aperyon
Автор

We set up static files in order to serve css files and other java files separately? is that the main reason? just making sure i understand.

travisestrada
Автор

Is it normal to Sublime Text to don't update files in folders project? I've been mad for a while with 'python manage.py collecstatic'. Firstly seems to have installed files in a folder inside django directory and afterwards, don't do anything. I've been doing again video 17 and when i left the external folder for static and take it again, the admin & img folders have appeared in the project!

VidAgendaConcertsCat
Автор

What do we do for production, if this is only good for development?

sierrakilo
Автор

When in debug mode...
I noticed that if commented out the line in urls.py
urlpatterns += static(settings.STATIC_URL,
then static files are served correctly. So my assumption is that in debug mode, static files located in apps/static and in STATICFILES_DIRS are served by the server automatically.
Why we should add the line?

michaelmarinos