前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Django1.8 CentOS7 N

Django1.8 CentOS7 N

作者头像
py3study
发布2020-01-02 16:47:05
3310
发布2020-01-02 16:47:05
举报
文章被收录于专栏:python3python3python3

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.

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

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Django
    • Install django
      • Start django
      • uwsgi
        • Install uwsgi
          • Start uwsgi
            • Stop uwsgi
              • Git pull
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档