1. 程式人生 > >Linux Django專案測試

Linux Django專案測試

步驟

django專案:


依賴包
[[email protected] ~]# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++  openssl-devel zlib zlib-devel -y

1.安裝python3
[[email protected] ~]# wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
[[email protected]
~]# tar xf Python-3.6.2.tgz [[email protected] ~]# cd Python-3.6.2/ [[email protected] Python-3.6.2]# ./configure --prefix=/usr/local/ [[email protected] Python-3.6.2]# make && make install [[email protected] Python-3.6.2]# ./configure && make && make install
2.安裝Django框架和uwsgi vim re.txt asn1crypto==0.24.0 beautifulsoup4==4.6.3 bs4==0.0.1 certifi==2018.4.16 cffi==1.11.5 chardet==3.0.4 Click==7.0 cryptography==2.3.1 Django==1.11.9 Flask==1.0.2 Flask-Cors==3.0.6 gevent==1.3.6 greenlet==0.4.15 idna==2.7 ItsDangerous==1.1.0 Jinja2==2.10 lxml==4.2.6
MarkupSafe==1.0 numpy==1.15.3 Pillow==5.3.0 pycparser==2.18 PyMySQL==0.9.2 pytz==2018.7 requests==2.19.1 selenium==3.141.0 six==1.11.0 urllib3==1.23 virtualenv==16.1.0 Werkzeug==0.14.1 wordcloud==1.5.0 pip3 install -i https://pypi.doubanio.com/simple/ -r re.txt pip3 install -i https://pypi.doubanio.com/simple/ uwsgi 3.測試uwsgi是否正常,新建 test.py檔案,內容如下: [[email protected] ~]# vim test.py def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello Django"] #然後在終端執行: 1.cd 到test.py目錄 2 uwsgi --http :8001 --wsgi-file test.py & 4.測試django是否正常,執行: [[email protected] ~]# django-admin.py startproject demosite [[email protected] ~]# cd demosite [[email protected] demosite]# vim settings.py 修改ALLOWED_HOSTS = ['*'] [[email protected] demosite]# python3 manage.py runserver 0.0.0.0:8002 在瀏覽器內輸入:http://伺服器ip:8002,檢查django是否執行正常。 5.配置uwsgi [[email protected] demosite]# vim /root/demosite/uwsgi.ini [uwsgi] socket = 127.0.0.1:9999 master = true workers = 2 #多少個併發處理 max-requests = 1000 #請求數響應 buffer-size = 30000 #記憶體使用 pidfile = /run/uwsgi.pid daemonize = /var/log/uwsgi.log uwsgi --ini /root/demosite/uwsgi.ini & 6.配置Nginx [[email protected] demosite]# vim /etc/nginx/conf.d/py.conf server { listen 80; server_name 10.0.0.100; client_max_body_size 100M; location / { index index.html; include uwsgi_params; uwsgi_pass 127.0.0.1:9999; uwsgi_param UWSGI_SCRIPT demosite.wsgi; uwsgi_param UWSGI_CHDIR /root/demosite; } } 重啟nginx