0
0
Djangoframework~10 mins

Static files in development in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add static files URL pattern in development.

Django
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # your url patterns here
] + static(settings.STATIC_URL, document_root=[1])
Drag options to blanks, or click blank then click option'
Asettings.MEDIA_ROOT
Bsettings.STATIC_ROOT
Csettings.TEMPLATES
Dsettings.BASE_DIR
Attempts:
3 left
💡 Hint
Common Mistakes
Using MEDIA_ROOT instead of STATIC_ROOT
Forgetting to import static from django.conf.urls.static
2fill in blank
medium

Complete the setting to enable static files serving in development.

Django
DEBUG = [1]
Drag options to blanks, or click blank then click option'
ATrue
B0
CFalse
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Setting DEBUG to False during development
Confusing DEBUG with other settings
3fill in blank
hard

Fix the error in the static files URL pattern code.

Django
from django.conf.urls.static import static
from django.conf import settings

urlpatterns += static(settings.STATIC_URL, document_root=[1])
Drag options to blanks, or click blank then click option'
Asettings.BASE_DIR
Bsettings.MEDIA_ROOT
Csettings.STATIC_ROOT
Dsettings.TEMPLATES_DIR
Attempts:
3 left
💡 Hint
Common Mistakes
Using MEDIA_ROOT instead of STATIC_ROOT
Not importing static or settings properly
4fill in blank
hard

Fill both blanks to create a dictionary comprehension for static files sizes.

Django
sizes = {file: os.path.getsize([1]) for file in os.listdir([2])}
Drag options to blanks, or click blank then click option'
Aos.path.join('static', file)
Bos.path.join(settings.STATIC_ROOT, file)
Csettings.STATIC_ROOT
D'static'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string 'static' instead of STATIC_ROOT
Not joining directory and file name for getsize
5fill in blank
hard

Fill all three blanks to filter static files by size greater than 1024 bytes.

Django
large_files = {file: size for file, size in sizes.items() if size [1] [2]

path = [3]
Drag options to blanks, or click blank then click option'
A>
B1024
Csettings.STATIC_ROOT
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > for filtering
Using wrong size value
Setting path to wrong directory