首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Django1.8 CentOS7 N

Django1.8 CentOS7 N

作者头像
py3study
发布于 2020-01-02 08:47:05
发布于 2020-01-02 08:47:05
38500
代码可运行
举报
文章被收录于专栏:python3python3
运行总次数:0
代码可运行

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

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
django-admin.py startproject xxc

start app

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
python manage.py startapp xxc_student

if you want to user pymysql, you should change __init.py__ as follow:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import pymysql

pymysql.install_as_MySQLdb()

after all, synchronous database

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
uwsgi --http-socket :8000 --chdir /opt/AnJiBei_Python_Project/anjibei/ --module django_wsgi

You can make uwsgi become a deamon with log.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
netstat -apn | grep 8000

Or, you can user the process name directly.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
netstat -apn | grep uwsgi

Later, use kill to stop the uwsgi deamon.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
kill -9 3532

Git pull

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/10/12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验