On linux, deploy the python django project. In the Django project, there are venv virtual environment files, how can I use this venv environment when starting the project

To deploy a Python Django project on Linux and use the venv virtual environment to start the project, you can follow the steps below:

  1. First, make sure you have installed Python and virtualenv on your Linux system. If it is not installed, use a package manager (such as apt, yum, etc.) to install it.

  2. Create a new virtual environment under the project root directory. Assuming your project root directory is /path/to/project, create a virtual environment with the following command:

    cd /path/to/project python3 -m venv venv

    venvThis will create a virtual environment called at the root of the project .

  3. Activate the virtual environment. Activate the virtual environment with the following command:

    source venv/bin/activate

    Note: After activating the virtual environment, you will notice a change in the terminal prompt, appearing in the prefix (venv).

  4. Install dependencies in the activated virtual environment. Execute the following commands in the virtual environment to install Django and other dependencies:

    pip install django

    You can requirements.txtlist all dependencies in a file and install them with:

pip install -r requirements.txt
  1. Perform database migrations. Go to the root directory of your Django project and execute the database migrations with the following command:

python manage.py migrate
  1. Start the Django project. In the virtual environment, start the Django project with the following command:

     
    python manage.py runserver

    By default, Django will start the project locally on 127.0.0.1port 8000. You can http://127.0.0.1:8000/view the project in your browser by visiting .

Note that the virtual environment will need to be reactivated every time you open a new terminal or log back in to use it. If you want to stop using the virtual environment, you can exit the virtual environment with the following command:

deactivate

Guess you like

Origin blog.csdn.net/qq_39208536/article/details/131417232
Recommended