Django serving static files locally

前端 未结 2 357
既然无缘
既然无缘 2021-01-19 19:51

It\'s been a while since I\'ve setup django to work locally. I\'m using version 1.11. Getting it to serve the static files. My project is called chatsys

相关标签:
2条回答
  • 2021-01-19 20:39

    Move your static folder under the base dir

    • chatsys
      • migrations
      • templates
      • etc.
    • static
      • css
        • style.css
    0 讨论(0)
  • 2021-01-19 20:52

    You should define STATICFILES_DIRS and include your project's static directory there.

    STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
    

    These are the directories that Django collects static files from.

    You should then change STATIC_ROOT to be a different directory. It is the directory that collectstatic collects static files to. The static root should not be under version control.

    As an aside, you are loading the static tag in your template but not using it. You could change it to:

    {% load static %}
    ...
    <link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
    
    0 讨论(0)
提交回复
热议问题