简体   繁体   English

如何在Django运行时中进行更改?

[英]How can I make changes in Django runtime?

I have hard time when developing django on my docker. 我在docker上开发Django时遇到了困难。 When I make any changes to the code, I need to restart whole container for the changes to take effect. 当我对代码进行任何更改时,我需要重新启动整个容器以使更改生效。

I have a filesystem mounted locally and the changes are made locally. 我在本地安装了文件系统,并且更改是在本地进行的。 But even if I make changes directly in the container, make migrations or touch an affected or wsgi file, the changes do not take any effect. 但是,即使我直接在容器中进行更改,进行迁移或touch受影响的文件或wsgi文件,更改也不会生效。

This is the image in compose file 这是撰写文件中的图像

backend:
    container_name: 'backend'
    image: dronetag/alpha-docker/backend
    build: ./images/backend/
    command: >
        sh -c  "
              python manage.py collectstatic --no-input;
              python manage.py migrate;
              gunicorn backend.wsgi -b 0.0.0.0:80;"
    ports:
      - "10080:80"
      - "10443:443"
    volumes:
      - ./src/backend:/src
    depends_on:
      - postgres
    links:
      - redis
      - postgres

Dockerfile Docker文件

FROM python:3.6
ENV PYTHONUNBUFFERED 1
ENV C_FORCE_ROOT true
RUN mkdir /src
WORKDIR /src
COPY requirements.txt .
RUN pip install -r requirements.txt

As long as you are in a development environment you can use the django development server and it will refresh everything accordingly. 只要您处于开发环境中,就可以使用django开发服务器,它将相应地刷新所有内容。

Just exchange gunicorn backend.wsgi -b 0.0.0.0:80 with python manage.py runserver . 只需将gunicorn backend.wsgi -b 0.0.0.0:80python manage.py runserver交换gunicorn backend.wsgi -b 0.0.0.0:80

Please note, that this is not suitable for a productive environment. 请注意,这不适合生产环境。 But there you usually do not need hot code reload. 但是,您通常不需要重新加载热代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM