Gunicorn cannot find static files after docking

I am using docker 17.05.0-cs edge on Ubuntu 17.04 Zesty. I have a gunicorn / Django app that I built here from here . It works fine before being closed, but firing can't see static files after docker build

. Here is Dockerfile

:

# Dockerfile

# FROM base image to build upon
FROM phusion/baseimage

# RUN install python and pip
RUN apt-get update
RUN apt-get install -y python python-pip python-dev 

# ENV set environment directory tree
ENV PROJECT=mysite
ENV CONTAINER_HOME=/opt
ENV CONTAINER_PROJECT=$CONTAINER_HOME/$PROJECT

# move to project WORKDIR
WORKDIR $CONTAINER_PROJECT

# COPY project to container directory
COPY . $CONTAINER_PROJECT

# RUN pip and install requirements
RUN pip install -r requirements.txt


# COPY start.sh into known container location 
COPY start.sh /start.sh

# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000

# CMD execute start.sh to start the server running.
CMD ["/start.sh"]
# done!

      

The app launches and displays the page, funny, even applies templates css

, saying it can't find bootstrap.css

or bootstrap.js

. However, it doesn't execute the script to switch the menu. The current templates are just an artifact of my original build, the new ones won't even be used bootstrap.js

I'm sure. It works, but the switch doesn't work, which I know is a function bootstrap.js

. This is the result sudo docker run -it -p 8000:8000 dockerized_site

:

Starting Gunicorn.
[2017-06-07 00:38:56 +0000] [1] [INFO] Starting gunicorn 19.6.0
[2017-06-07 00:38:56 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
[2017-06-07 00:38:56 +0000] [1] [INFO] Using worker: sync
[2017-06-07 00:38:56 +0000] [9] [INFO] Booting worker with pid: 9
[2017-06-07 00:38:56 +0000] [10] [INFO] Booting worker with pid: 10
[2017-06-07 00:38:56 +0000] [11] [INFO] Booting worker with pid: 11
Not Found: /js/bootstrap.min.js
Not Found: /js/jquery.js
Not Found: /js/bootstrap.min.js
Not Found: /favicon.ico

      

I've attached a static file template template to urls.py

, I'm pretty sure it has to do with the container build, or maybe with settings.py

. Perhaps I need to add the environment directory for static files? Any help is of course appreciated.

+1


source to share


2 answers


It's your problem:

Yours css

works fine:

<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">

      

Yours js

doesn't work (404):

<script src="{% static '/js/jquery.js' %}"></script>

      



See the difference?

Leading /

the way to / js

This fixes the problem:

<script src="{% static 'js/jquery.js' %}"></script>

      

I cloned your repo and patched the templates and I resolved to fix your problem. Please correct another <script>

s

+1


source


See https://docs.djangoproject.com/en/1.11/howto/static-files/deployment/ for deploying static files.



But you can use your static files using a web server like Nginx or Apache. You shouldn't use Gunicorn to serve static files, especially in production. Gunicorn is a WSGI server built for dynamic content.

+1


source







All Articles