您好,登錄后才能下訂單哦!
作者: 何全,github地址: https://github.com/××× QQ交流群: 62-01-76-50-1
通過此教程完成從零入門,能夠獨立編寫一個簡單的CMDB系統。
目前主流的方法開發方式,分為2種:mvc 和 mvvc方式。本教程為 mvc 方式,即 django負責渲染html。后面會推出 mvvc(前后端分離)的入門教程。
教程項目地址: https://github.com/×××/husky/
教程文檔地址: https://github.com/×××/husky/tree/master/doc
框架是整個或部分系統的可重?設計,表現為一組抽象構件及構件實例間交互的?法; 另一種定
義認為,框架是可被應用開發者定制的應用骨架。Django是Python下的一款著名的Web框架。
需要你有python基本代碼編寫能力 以及 html js 基礎, 對django有一個大概了解。
yum install epel-release -y
yum -y install sqlite sqlite-devel
yum install python-devel mysql-devel python36-devel.x86_64 -y
sudo yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum install python36 python36-setuptools -y
easy_install-3.6 pip
python3.6 -m pip install --upgrade pip
mv /usr/bin/python /tmp/
ln -s /usr/bin/python3.6 /usr/bin/python
sed -i 's/\#\!\/usr\/bin\/python/\#\!\/usr\/bin\/python2/' /usr/bin/yum
sed -i 's/\#\! \/usr\/bin\/python/\#\! \/usr\/bin\/python2/' /usr/libexec/urlgrabber-ext-down
mkdir -p /root/.pip/
cat > /root/.pip/pip.conf <<EOF
[global]
trusted-host=mirrors.aliyun.com
index-url=http://mirrors.aliyun.com/pypi/simple/
EOF
python -V
pip3 install django==2.2.6
file-->settings-->project interpreter--> add --> ssh interpreter 設置遠端 python環境
設置/usr/bin/python3.6 目錄選擇 <Project root>→/opt
file--> new project --> django
mkdir -p /data/docker
mkdir -p /data/mysql5722
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum -y install docker-ce
docker version
systemctl enable docker.service
systemctl start docker.service
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors": ["https://890km4uy.mirror.aliyuncs.com"],"graph": "/data/docker"}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
mkdir -p /data/mysql5722
mkdir -p /data/mysql5722-cnf
docker run -itd \
--name mysql \
-p 3306:3306 \
--mount type=bind,src=/data/mysql5722,dst=/var/lib/mysql \
--mount type=bind,src=/data/mysql5722-cnf,dst=/etc/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:5.7.22 --character-set-server=utf8
yum remove mariadb -y
yum install mariadb -y
mysql -uroot -p123456 -h 192.168.100.99
create database husky;
husky --> settings
ALLOWED_HOSTS = ['*'] ##允許所有地址訪問
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '192.168.100.99',
'PORT': '3306',
'NAME': 'husky',
'USER': 'root',
'PASSWORD': '123456',
}
}
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
# }
vim /usr/local/lib64/python3.6/site-packages/django/db/backends/mysql/base.py
35 #if version < (1, 3, 13): 注釋掉 這兩行
36 # raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
vim /usr/local/lib64/python3.6/site-packages/django/db/backends/mysql/operations.py
145 if query is not None:
146 query = query.encode(errors='replace') ##修改此行
pycharm : 菜單欄 tools --> 選擇 run manage.py task
makemigrations 生成數據文件
migrate 根據文件,執行生成表結構
createsuperuser
設置pycharm 項目啟動 地址 為 192.168.100.99
pycharm 啟動django項目 (非命令行啟動)
ssh://root@192.168.100.99:22/usr/bin/python3.6 -u /opt/manage.py runserver 192.168.100.99:8000
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
October 31, 2019 - 09:33:33
Django version 2.2.6, using settings 'husky.settings'
Starting development server at http://192.168.100.99:8000/
Quit the server with CONTROL-C.
測試登錄 http://192.168.100.99:8000/admin 輸入賬號密碼
創建 requirements.txt 文件
pip3 freeze > requirements.txt
pip3 install -r requirements.txt ## 安裝所有模塊,如有增加模塊,需要加到這里面
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。