sqlitedjango入门–django-blog-zinnia搭建筑私房博客

1、安装python

  选择并适python2.7跟以上版本安装https://www.python.org/downloads/

2、建立虚拟环境

  这不是得的,但是建议使用,为每个门类单独引入依赖,避免出现环境问题。对于python3.3以下版本可参考https://virtualenv.pypa.io/en/stable/installation/,python3.3及以上版本参考https://docs.python.org/3/library/venv.html。

3、安装必要的乘

  • Python >= 2.7
  • Django >= 1.10
  • Pillow >= 2.0.0
  • django-mptt >=
    0.8.6
  • django-tagging >=
    0.4.5
  • beautifulsoup4 >=
    4.1.3
  • mots-vides >=
    2015.2.6
  • regex >= 2016.3.2
  • django-contrib-comments >=
    1.7

4、建立django项目

  django-admin startproject
mysite,mysite表示您的项目名称。django详细入门教程参考https://docs.djangoproject.com/en/1.11/intro/tutorial01/

5、修改mysite目录下之setting.py

  将INSTALLED_APPS 修改如下:

INSTALLED_APPS = (
  'django.contrib.auth',
  'django.contrib.admin',
  'django.contrib.sites',
  'django.contrib.sessions',
  'django.contrib.messages',
  'django.contrib.staticfiles',
  'django.contrib.contenttypes',
  'django_comments',
  'mptt',
  'tagging',
  'zinnia',
)

  修改TEMPLATES 

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

STATIC_ROOT = os.path.join(BASE_DIR, "static/")

SITE_ID = 1#对应数据库中站点id

5、配置html文件

  在mysite文件夹着建立templates文件夹,将package中之模版,位于Lib\site-packages\zinnia\templates,拷贝到templates中,根据需要修改base.html中相关内容

  python manage.py collectstatic

6、迁移数据库

  运行 python mange.py
 migrate,会活动创建连锁数据库文件,使用的凡sqlite3数据库,可以另行setting.py中改

7、创建管理员

  python manage.py
createsuperuser,可由此顾http://127.0.0.1:8000/admin/ 进行披露篇

8、启动

  python mange.y runserver

 

demo参见https://demo.django-blog-zinnia.com/blog/

 

使用uWSGI和nginx来设置Django和你的web服务器

1、安装新型稳定版nginx

  参考http://nginx.org/en/linux\_packages.html\#stable,例如在centos6上,创建/etc/yum.repos.d/nginx.repo这个文件,写入以下内容,然后执行yun
install nginx

  [nginx]
  name=nginx repo
  baseurl=http://nginx.org/packages/centos/6/$basearch/
  gpgcheck=0
  enabled=1

2、安装python3,服务器并未python3,可以据此源码安装,注意centos6达到源码安装的恐怕没有sqllite3承保,可以经过如下方式缓解

  yum install sqlite-devel

  ./configure –enable-loadable-sqlite-extensions && make && sudo make
install

  参考http://stackoverflow.com/questions/1210664/no-module-named-sqlite3

3、配置nginx

upstream django {
    server unix:///home/www/mysite/mysite.sock; # for a file socket,指向你启动uwsgi的目录的mysite.sock文件
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name example.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /uploads  {
        alias /home/www/zinnia-blog/uploads;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/www/zinnia-blog/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
    }
}

 

  将这文件放置到nginx的布置目录,覆盖默认的布置就可以了。重开nginx

 

4、安装 uwsgi

  pip install uwsgi

5、启动服务

uwsgi –socket mysite.sock  –module mysite.wsgi –master -p 1 –threads
8 –daemonize log.txt

以会见创mysite.sock文件

 

sqlite 1

网站地图xml地图