STATIC_ROOT in Django on Server

前端 未结 1 1320
情话喂你
情话喂你 2020-12-30 12:17

I\'m 2hours stuck in a issue about STATIC_URL and STATIC_ROOT when I try to make run the webapp on my server at webfactional.

when I load the webpage all the request

相关标签:
1条回答
  • 2020-12-30 12:43

    2 things must happen on a production environent that is not needed in the development environment.

    You must run manage.py collectstatic -- this collects all static files into your STATIC_ROOT directory.

    You must serve your STATIC_ROOT directory at the STATIC_URL url. How exactly depends on your production setup. This is not even django related; all that matters is that STATIC_ROOT contents are available at STATIC_URL.

    Let's say you're using Apache, you'd alias a URL to a directory.

    Alias /static/ /path/to/my/static_root/
    

    If you're using nginx, it would be something like

    location = /static/ {
        alias /path/to/my/static_root/;
    }
    

    I just realized you're using webfaction, in which case you set up a static application which literally just serves files at the targeted directories at the URL you define. I'm trying to remember my webfaction login to see the exact procedure, but it shouldn't be difficult to figure out.

    Update: Logged into webfaction; you can create an application that is a symlink. Easy!

    Create a symbolic link app that serves /YOUR_STATIC_URL/ and point it to /YOUR_STATIC_ROOT/. Done!

    0 讨论(0)
提交回复
热议问题