There is no particular vision , I just hope everything goes smoothly
mkdir Folder
git clone Warehouse url
# Create a virtual environment and specify PYTHON edition
# 2.7
virtualenv venv --python=python2.7
# 3.6
# Method 1
virtualenv venv --python=python3.6
# Method 2
python3 -m venv venv(2、3 Environmental coexistence )
perhaps
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python manage.py runserver 0:9900
When two versions of a host exist at the same time python(2.7&3.8) when , Generally, the system PATH The one configured in
however
Use pip and python Command wake up 2.7, Use pip3 and python3 Command wake up 3.8
2.7python With all versions mysql adapter , And adaptation django1.10
3.6python With all versions django Adaptation and adaptation mysql8.0
The structure class in which the table is written function
python manage.py makemigrations app name
python manage.py migrate app name
Generate data table
By importing models.py File to create data
from blog import models
def db_handle(request):
models.UserInfo.objects.create(username=‘andy’,password=‘123456’,age=33)
return HttpResponse(‘OK’)
Modifying data :filter(id=1).update(age=18)# find id=1 The data of , take age Change it to 18
Configure the routing , visit views.py file
from blog import views
urlpatterns = [
url(r’^admin/’, admin.site.urls),
url(r’^test’, views.db_handle),==> Point to test The routing , Jump to views.db_handle Method , perform t1.html page
# notes :lrhold/abc It represents the... Under the root directory abc file , and domain/abc/ refer to abc In the catalog default file , With or without slashes is often used in SEO Optimize
]
Path to the configuration template
TEMPLATES=[
{
…
‘DIRS’: [os.path.join(BASE_DIR,‘templates’)],# Configure template path
},]
pip install PyMySQL
modify : The configuration file is the same as that in the directory init.py
import pymysql
pymysql.install_as_MySQLdb()
perhaps
pip install mysqlclient
Method 1.
modify settings Medium DATABASES Variable
Method 2.
The database configuration is stored in mysql.cnf
stay settings I quote :
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DATABASES = getDatabase(BASE_DIR)
import platform
import os
def getDatabase(base_dir):
p = platform.system()
if p == 'Windows':
return {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
"read_default_file": os.path.join(base_dir, 'mysqltest.cnf'),
}
}
}
else:
return {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
"read_default_file": os.path.join(base_dir, 'mysql.cnf'),
}
}
}
pip3 install django== Version number
django-admin startproject blog_project ==》cd( Be careful not to. .py)
python manage.py startapp blog
python manage.py runserver 8000
python -m django --version
1.django When connecting to the database, the page displays url Variable mismatch : take url The first variable is null
urlpatterns = [
url('^', admin.site.urls),
url('^', index, name='index'),
]
2. To configure settings.py==>INSTALLED_APP add to app name
3. To configure settings.py==>ALLOWED_HOSTS = [‘10.xxx.xxx.xxx’,]
4. Use vscode Of sftp Connect remote linux Prompt permission error , Should be rolled back vscode Version to 1.34
5.windows No, python-dev package , Nor in windows Upper Department ngnix+uswgi The server ,pip Installation will fail
1. start-up :uwsgi --ini uwsgi.ini
2. Write a ngnix.conf Put under Project , Put this conf Soft link or move to /etc/nginx/sites-enabled/ below , Last service nginx reload
[uwsgi.ini]
# Use 9100 port
http= :9100
#socket = :9100
# Project location mysite It's my project name
chdir = /home/liting/projects/demand-management/logsites
# Change it to your own project name
module = logsites.wsgi
# Virtual environment Directory env Is my server virtual environment name
home = /home/liting/workspace/Envs/env3
master = true
# The biggest working process , Generally, it is set according to the number of cores , It can also be set arbitrarily
processes = 4
vacuum = true
# Log files
daemonize = /home/liting/projects/demand-management/logsites/uwsgi.log
# Static file directory
static-map = /static=/home/liting/projects/demand-management/logsites/static
pidfile=uwsgi.pid
daemonize=uswgi.log
[nginx.conf]
server {
listen 80;
server_name 10.xxx.xxx.xxx:9100;
charset utf-8;
client_max_body_size 75M;
# Change to your media file directory
location /media {
alias /home/liting/projects/demand-management/logsites/media; # your Django project's media files - amend as required
}
# Change to your static file directory
location /static {
alias /home/liting/projects/demand-management/logsites/static; # your Django project's static files - amend as required
}
location / {
# This is the top uwsgi.ini Set up 8080 port , Be consistent ,nginx Even with this and uwsgi communication
uwsgi_pass 10.xxx.xxx.xxx:9100;
include /etc/nginx/uwsgi_params;
}
}
Reference resources https://www.zmrenwu.com/courses/hellodjango-blog-tutorial/materials/80/