Django1.8 CentOS7 Nginx uwsgi

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.

Django

I used it in august 2015, later i found Flask with Gunicorn is better way to finish a small project.

Install django

This is needless to say, it is ok to use pip.
Recommend a source image: https://pypi.doubanio.com/simple/

Start django

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

uwsgi

Install uwsgi

These were some error you may encounter:

  • uwsgi: option '--http' is ambiguous

The problems associated with the environment of python,it is recommented to use pip install uwsgi to install uwsgi

  • ImportError: No module named 'wsgi'

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 uwsgi

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:

  • Static resource access failure

Run python manage.py collectstatic,and static files will be copied to the STATIC_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...

Stop uwsgi

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

Git pull

You have to restart the uwsgi to make you code to take effect.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值