The deployment set for a long time, at first i met the environment problem which is my code based on Python3.4. Python2.7 and python3.4 conflict. So, i try to use virtualenv
to make it success, and i have to do many works again.
I used it in august 2015, later i found Flask
with Gunicorn
is better way to finish a small project.
This is needless to say, it is ok to use pip
.
Recommend a source image: https://pypi.doubanio.com/simple/
start project
django-admin.py startproject xxc
start app
python manage.py startapp xxc_student
if you want to user pymysql
, you should change __init.py__ as follow:
import pymysql
pymysql.install_as_MySQLdb()
after all, synchronous database
python3 manage.py syncdb
These were some error you may encounter:
The problems associated with the environment of python,it is recommented to use
pip install uwsgi
to install uwsgi
Wsgi configuration file with the manage.py in the same directory,there are many kinds of format wsgi configuration file,such as
.wsgi
and.py
, you can use both of them in the same way.
start command, this command is a test way to run the Django.
uwsgi --http-socket :8000 --chdir /opt/AnJiBei_Python_Project/anjibei/ --module django_wsgi
You can make uwsgi become a deamon with log.
uwsgi --http-socket :8000 --chdir /opt/AnJiBei_Python_Project/anjibei/ --module django_wsgi --daemonize /opt/AnJiBei_Python_Project/anjibei/log/uwsgi.log
Also important is that django_wsgi
is the configuration file which should be in the same directory with manage.py
.Don't write an absolute path, otherwise, may lead to the import error
.
These were some error you may encounter:
Run
python manage.py collectstatic
,and static files will be copied to theSTATIC_ROOT
specified static folder.
This command feels a bit strange, my static files distribution under different startapp, now, all of them... hum... be synchronized.The location of the static files were affected by the position where you execute the uwsgi
command. So, you can find the static files were in the same directory with manage.py
. Here is a picture of original, but... you know...
Just we specify th 8000 port, so we can use it to find the process no.
netstat -apn | grep 8000
Or, you can user the process name directly.
netstat -apn | grep uwsgi
Later, use kill
to stop the uwsgi deamon.
kill -9 3532
You have to restart the uwsgi to make you code to take effect.
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有