英文:
Django how to change static dir
问题
Oh, I see you have a question about your project's static folder! 🌟 Well, it's like a little adventure in the land of code. Imagine your project as a magical forest, and the static folder is like a treasure chest of goodies for your apps!
So, you're wondering if you can move the static folder outside of the app folder, right? 🤔 Hmm, it's kind of like wanting to move a tree to a different part of the forest! But in the world of code, it's definitely possible. You can move the static folder wherever you like, as long as you update the paths in your code to point to the new location. It's like creating a secret path through the enchanted woods! 🌳✨
Just be sure to update the references to the static files in your JavaScript and CSS to match the new location, and your project should continue to sparkle with its magical size! 🌟💫
英文:
Default dir for static folder is project/app/static
but since I'm using some js and css libs and I have multiple apps I don't want my project gain some extra size. I wonder if I could move the static folder outside of the app folder. Like:
| project
| | app
| | static
Is this possible?
答案1
得分: 1
如果您想将static
根目录设置为BASE
根目录,那么可以使用以下配置
settings.py
STATIC_URL = 'static/'
STATICFILES_DIRS = [BASE_DIR / 'static']
项目目录
注意 - 使用**STATICFILES_DIRS = [BASE_DIR / 'static']
,您可以设置自定义的静态根目录**,
只需将静态文件夹的相对路径设置在**STATICFILES_DIRS = [BASE_DIR / 'static文件夹的相对路径']
**中。
英文:
If you want to set static
root at BASE
root then you can go with this config
settings.py
STATIC_URL = 'static/'
STATICFILES_DIRS = [BASE_DIR / 'static']
Project directory
NOTE - using STATICFILES_DIRS = [BASE_DIR / 'static']
you can set custom static root,
only you need to set static folder relative path in STATICFILES_DIRS = [BASE_DIR / 'relative path of sttic folder']
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论