django deployed to the server using a simple test manage.py runserver

Django project for the first time to deploy to the cloud server, in order to want a quick look at the effect of remote access, but unexpectedly stepped on a lot of pit

Explain, for the production of projects recommended for nginx + uWSGI + virtualenv + django, and this is just one step description of real production, the rapid deployment django code is to test whether the server and can be accessed remotely.

 

Development Environment: python3.5.4 + django2.2.10

 

1. Ali cloud cloud server rental, choose a mirror Ubuntu16.04 (preinstalled python2.7.12 and python3.5.2)

 

2. In order to solve python2 bring unnecessary trouble, first use the command to change the default python3

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.5 /usr/bin/python 

 

3. Install the package management tool for easy management

sudo apt-get install python3-pip

May be upgraded after installation pip, follow the prompts to upgrade click on it

 

4.pip installation virtualenv

pip install virtualenv

 

5. Move the item to the server / var / www

 

6. Create a virtual environment kvnv in / var / www inside

virtualenv kvenv

 

7. Use the command to enter the virtual environment

source kvenv/bin/activate

 

 

 Will appear in front of the command line (venv) that we are running in a virtual environment

 

8. Installation django packages and other dependencies in a virtual environment

pip install django==2.2.10

 

9. still in a virtual environment, into the project, modify settings.py with vim

Modify the configuration to allow access to other ip

ALLOWED_HOSTS = ['*']


10. Back to the project, use the command in a virtual environment

python manage.py runserver 0.0.0.0:80

11. Use your own computer to access the public network server ip to see django project will run correctly in the server environment.

 

Guess you like

Origin www.cnblogs.com/wangzhihang/p/12365990.html