Preliminary discussion on django-demo charade using virtualenv to configure the project to deploy under CENTOS7

Source: Internet
Author: User
Tags virtualenv

Preliminary discussion on django-demo charade using virtualenv to configure the project to deploy under CENTOS7

=======================================

2016/1/18


# # # #charade is a small game of guessing words.

Https://github.com/opera443399/charade

Prepare-------1. pip+virtualenv+django ::        [[email  protected] ~]# yum install python-pip         [[email protected] ~]# pip install virtualenvwrapper         [[email protected] ~]# mkdir /opt/.virtualenvs /opt/. pyprojects        [[email protected] ~]# echo  ' Export workon_home=/opt/.virtualenvs '  >>~/.bashrc         [[email protected] ~]# echo  ' export project_home=/opt/.pyprojects '  > >~/.bashrc        [[email protected] ~]# echo  ' Source /usr/bin/virtualenvwrapper.sh '  >>~/.bashrc             [[email p rotected] ~]# source ~/.bashrc        [[email  protected] ~]# mkproject django_web         (Django_web) [[email protected] django_web]# pip install django2.  Adjustment  project  setting ::         (Django_web) [[Email protected] django _web]# django-admin startproject www         (Django_web ) [[email protected] django_web]# cd www         ( Django_web) [[email protected] www]# vim www/settings.py          add app, adjust language and time zone, configure file to add the path of static directory at last               INSTALLED_APPS = [                  (omitted)                   ' Charade ',                  ' polls ',            ]             LANGUAGE_CODE =  ' ZH-CN '              TIME_ZONE =  ' Asia/shanghai '  3.  Copy the code from the above 2 apps to the project directory  ::     (omitted) 4.  adjust  project urls ::          (Django_web) [[email protected] www]# vim  Www/urls.py            from django.conf.urls  import url, include             from django.contrib import Admin            from charade import  views                 urlpatterns = [                 url (R ' ^$ ',  views.index, name= ' index '),                 url (R ' ^charade/',  include (' Charade.urls ',  namespace= ' Charade ')),                 URL (r ' ^polls/',  include (' Polls.urls ',  namespace= ' polls ')),                 url (R ' ^admin/',  include (admin.site.urls)),5.  Build Database  ::         (django_web) [[email protected] www]#  python manage.py migrate         (Django_web) [[email protected] www]#  python manage.py makemigrations charade         ( Django_web) [[email protected] www]# python manage.py sqlmigrate charade  0001         (Django_web) [[Email protected] www]# python  manage.py makemigrations polls         (Django_web) [[ email protected] www]# python manage.py sqlmigrate polls 0001          (Django_web) [[email protected] www]# python manage.py  migrate6.  try to run the  ::         (django_web) [[email  protected] www]# python manage.py runserver 0.0.0.0:80     test Basic functions, For example, we used: Pytz, need to install, otherwise will be reportedWrong:             exception type:i mproperlyconfigured        exception value:         this query requires pytz, but it isn ' t  installed.         (Django_web) [[email protected] www]#  pip install pytz              After confirming that the data in the background is read and written without exception, it will be stopped and subsequently managed using UWSGI. 7. admin Backstage  ::         (Django_web) [[email protected]  www]# python manage.py createsuperuser         Http://0.0.0.0/admin/8. debug ::        DEBUG=False, Django does not process static files, you should configure Nginx or Apache to handle static files. Uwsgi+supervisord+nginx----------------------1.  Installation  ::        [[email protected] ~]# yum install nginx python-devel         [[email protected] ~]# yum groupinstall  " Development tools "        [[email protected] ~]#  pip install supervisor        [[email protected] ~ ]# whereis supervisord        supervisord: /usr/bin/ supervisord /etc/supervisord.conf                  (Django_web) [[email protected] www]# pip install uwsgi          (Django_web) [[email protected] www]# whereis  uwsgi        uwsgi: /opt/.virtualenvs/django_web/bin/uwsgi     2.&nbSP; configure  ::    1)   Turn off the  DEBUG  options for the Django project and set  ALLOWED_HOSTS  and  STATIC_ROOT :             (Django_web) [[ email protected] www]# vim www/settings.py         debug = false                 allowed_hosts = [' * ']                 static_root = os.path.join (Base_dir, ' STATIC ')          2)   Collect the static files for the Django project:              (Django_web) [[Email protected] www]# python manage.py collectstatic         3)   Use supervisor to manage UWSGI services, run django:   with Uwsgi     &nbSp;     [[email protected] ~]# # echo_supervisord_conf >  /etc/supervisord.conf         && mkdir / etc/supervisor.d         && echo -e  ' [ Include]\nfiles=/etc/supervisor.d/*.ini '  >>/etc/supervisord.conf          && grep ^[^\;]  /etc/supervisord.conf                 [[email protected] ~]# whereis supervisord         4)   Start  supervisord  service:             [[email protected] ~]# /usr/bin/supervisord -c /etc/ supervisord.conf        [[email protected] ~]# echo  '/usr/bin/supervisord -c /etc/supervisord.conf '  >>/etc/rc.local         5)   Configure UWSGI service:             [[email protected] ~]# cat /etc/supervisor.d/uwsgi.ini          [program:uwsgi]         command=/opt/.virtualenvs/django_web/bin/uwsgi --socket 127.0.0.1:8090 --chdir /opt/. pyprojects/django_web/www --module www.wsgi             6) Start-up  uwsgi  service:             [[email protected] ~]# supervisorctl reload         restarted supervisord        [[email protected]  ~]# supervisorctl status        uwsgi                              RUNNING   pid 22023, uptime 0:00:05              Instructions:        uwsgi  using  -- socket  means: Access through the socket, so the subsequent can be accessed using the  nginx uwsgi  module.         uwsgi  using  --http  means: can be accessed directly through  http, So the follow-up can be accessed with  nginx proxy .             7)   Use Nginx to handle static files and forward requests to the backend Uwsgi service             a) nginx uwsgi         [[email protected] ~]# cat /etc/nginx/conf.d/www.conf          server {             Listen 80 default;            server_ name www.test.com;            charset  utf-8;                     location /static {                 alias /opt/.pyprojects/django_web/www/static;             }                     location / {                 uwsgi_pass 127.0.0.1:8090;                 include uwsgi_params;             }        }                 B) nginx proxy         [[email protected] ~]# cat /etc/nginx/conf.d/ www.conf         upstream backend {             server 127.0.0.1:8090;         }                 server {            listen  80 default;            server_name  www.test.com;            charset utf-8;                          location /static {                 alias /opt/.pyprojects/django_web/www/static;             }                     location / {                 proxy_pass http://backend;             }        }                  (CENTOS7)          [[email protected] ~]# systemctl start nginx.service         [[email protected] ~]# systemctl enable nginx.service


Preliminary discussion on django-demo charade using virtualenv to configure the project to deploy under CENTOS7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.