Django REST framework+Vue to create a fresh supermarket (10) 11. pycharm remote code debugging

Django REST framework+Vue to create a fresh supermarket (10) 11. pycharm remote code debugging

Eleven, pycharm remote code debugging

 Third-party login and payment require a server (callback url), we can use pycharm to remotely debug the server code

Server environment construction

Take the new Alibaba Cloud centos7 system as an example:

11.1. Alibaba Cloud Security Group Configuration

Quickly create rules, select commonly used ports, authorized objects, and confirm it.

Also add a security group rule, set the port range, authorization object, click OK

ssh connection

 yum install openssh-server -y

service sshd restart

#xshell can't connect, the SSH server does not allow password authentication.
#Server to open password verification method:


Set the PasswordAuthentication item to yes

Restart service

service sshd restart

11.2.mysql installation

#1. Installation
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server

#2. Restart the service
service mysqld restart

#3. Set bind-ip

    In [mysqld]:
        Add one line below
        bind-address =

#4. Log in to mysql
mysql -u root

#5. Set external ip to be accessible
#mysql enter the command:
#Use Navicat to connect to the remote server mysql username and password later


#6. Set mysql password
Enter mysql:
set password =password('123456'); #PASSWORD123456
flush privileges;

11.3. Installation of pip and python3.6

#Install pip

wget --no-check-certificate

sudo python
#Install python3.6
Install these two first

yum -y install zlib*

yum install openssl-devel -y

1. Obtain

tar -xzvf Python-3.6.2.tgz -C/tmp

2. Install Python 3.6 to the/usr/local directory

./configure --prefix=/usr/local
make altinstall

3. Change/usr/bin/python link

ln -s/usr/local/bin/python3.6/usr/bin/python3

11.4. Virtual environment installation

yum install python-setuptools python-devel
pip install virtualenvwrapper

#Edit .bashrc file
vim ~/.bashrc

#Add to
export WORKON_HOME=$HOME/.virtualenvs

#sudo find/-name Check where your is

#Reload the .bashrc file
source ~/.bashrc

#Virtual environment saved path
cd ~/.virtualenvs/(The created virtual environment will be saved in this directory, which was set earlier)

#Create a virtual environment method for the specified python version
mkvirtualenv MxShop --python=python3.6

workon MxShop

#Enter the virtual environment to install the dependency package

1. pip freeze> requirements.txt export the local virtual environment installation package and upload it to the server

pip install -r requirements.txt

#Install mysqlclient problem

    centos 7:
        yum install python-devel mariadb-devel -y

        sudo apt-get install libmysqlclient-dev

        pip install mysqlclient

11.5. navicat remote connection to transfer data

Use Navicat to remotely connect to the database

  • ip: your server ip
  • Username: root
  • passwd:123456

Then create a new database

 After the database is built, start to transfer the data in the local database to the remote server

11.6. pycharm remote debugging code

(1) Tools-->>Deployment-->>Configuration

(2) Connect and Mappings settings

 After setting, click "Test SFTP connection" to connect to the database, and then transfer the project code to the remote database last time

Tools-->>Deployment-->>Configuration-->>Upload to MxShop

(3) Server operation project

python runserver

Found an error

 The allowed HOST must be set in the settings, and the HOST in the database must also be set to the ip of the server

    'default': {
        'NAME':'mxshop', #database name
        'USER':'root', #account
        'PASSWORD': '123456', #Password
        'HOST': '', #IP
        'PORT': '3306', #Port
        #Here the engine uses innodb (default myisam)
        #Because the third-party login requires the engine to be INNODB
        #'OPTIONS':{'init_command':'SET storage_engine=INNODB'}, #According to the course, an error will be reported, change to
        "OPTIONS":{"init_command":"SET default_storage_engine=INNODB;"}

After setting, synchronize the settings file to the server

Run the project again, you can access it normally

 (4) pycharm remote debugging code

The interpreter of pycharm is set to the python of the server virtual environment, which is equivalent to running the project on the server

Then it will copy all the files in the server virtual environment to the local

After clicking "ok", some things will be loaded, wait patiently for a while, and when finished

 Set Host port 8000

 Running the project on pycharm is equivalent to running the project on the server

Reference: Django REST framework+Vue to create a fresh supermarket (10) 11. pycharm remote code debugging-Cloud + Community-Tencent Cloud