0
0
Djangoframework~20 mins

collectstatic for production in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Static Files Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you run python manage.py collectstatic in Django?

In a Django project, you run python manage.py collectstatic. What is the main effect of this command?

AIt copies all static files from each app and places them into the directory specified by <code>STATIC_ROOT</code>.
BIt deletes all static files from the project to free up space.
CIt compiles Python code into bytecode for faster execution.
DIt runs the development server to serve static files automatically.
Attempts:
2 left
💡 Hint

Think about where static files need to be collected for production deployment.

📝 Syntax
intermediate
1:30remaining
Which setting must be set correctly for collectstatic to work?

To use collectstatic properly, which Django setting must point to an absolute directory path where static files will be collected?

AMEDIA_ROOT
BSTATIC_URL
CSTATIC_ROOT
DTEMPLATES_DIR
Attempts:
2 left
💡 Hint

This setting defines the folder where static files are gathered for production.

state_output
advanced
2:00remaining
What is the output of collectstatic if STATIC_ROOT is not set?

You run python manage.py collectstatic but forgot to set STATIC_ROOT in your settings. What will happen?

AIt raises an error saying <code>You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.</code>
BIt runs successfully but does not copy any files.
CIt collects static files into the default <code>staticfiles</code> folder automatically.
DIt ignores static files and only collects media files.
Attempts:
2 left
💡 Hint

Think about what Django requires to know where to put collected files.

🔧 Debug
advanced
2:30remaining
Why are static files not updating after running collectstatic?

You updated some CSS files in your app and ran python manage.py collectstatic. However, the changes are not visible in production. What is a likely cause?

AYou forgot to restart the Django development server.
BThe web server is caching old static files; browser or server cache needs clearing.
CThe <code>STATIC_URL</code> setting is missing in <code>settings.py</code>.
DYou need to run <code>python manage.py migrate</code> to update static files.
Attempts:
2 left
💡 Hint

Static files are often cached by browsers or servers to improve speed.

🧠 Conceptual
expert
3:00remaining
Why is collectstatic important for production but not for development?

Explain why Django projects require running collectstatic before deploying to production, but not during development.

AIn development, static files are compiled on the fly; in production, they are converted to Python bytecode.
BIn development, static files are ignored; in production, they are embedded inside HTML templates.
CIn development, static files are stored in the database; in production, they must be collected into the file system.
DIn development, Django serves static files automatically; in production, static files must be collected and served by a web server for efficiency and security.
Attempts:
2 left
💡 Hint

Think about how Django handles static files differently in development vs production environments.