blog开发环境环境设置

Posted 喵吉欧尼酱

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了blog开发环境环境设置相关的知识,希望对你有一定的参考价值。

所需要环境:

  win10

  python 2.7.10

  django 1.10.6

  mysql  

  mysql-python 

  pillow


 

├─.idea
├─blog
│ └─migrations
├─Blog_project
├─static
└─templates

setting设置

LANGUAGE_CODE = \'zh-hans\'# 语言
TIME_ZONE = \'Asia/Shanghai\' #时区

USE_I18N = True

USE_L10N = True

USE_TZ = False #Ture 国际时间 False  本地时间

 

static设置

STATIC_URL = \'/static/\'
STATICFILES_DIRS=[
    os.path.join(BASE_DIR,\'static\')
]

templates设置

     \'DIRS\': [os.path.join(BASE_DIR, \'templates\')]

APP注册

INSTALLED_APPS = [
    \'django.contrib.admin\',
    \'django.contrib.auth\',
    \'django.contrib.contenttypes\',
    \'django.contrib.sessions\',
    \'django.contrib.messages\',
    \'django.contrib.staticfiles\',
    \'blog\',
]

 

日志配置

# 自定义日志输出信息
LOGGING = {
    \'version\': 1,
    \'disable_existing_loggers\': True,
    \'formatters\': {
        \'standard\': {
            \'format\': \'%(asctime)s [%(threadName)s:%(thread)d] [%(name)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s]- %(message)s\'}  #日志格式
    },
    \'filters\': {
    },
    \'handlers\': {
        \'mail_admins\': {
            \'level\': \'ERROR\',
            \'class\': \'django.utils.log.AdminEmailHandler\',
            \'include_html\': True,
            },
        \'default\': {
            \'level\':\'DEBUG\',
            \'class\':\'logging.handlers.RotatingFileHandler\',
            \'filename\': \'log/all.log\',     #日志输出文件
            \'maxBytes\': 1024*1024*5,                  #文件大小
            \'backupCount\': 5,                         #备份份数
            \'formatter\':\'standard\',                   #使用哪种formatters日志格式
        },
        \'error\': {
            \'level\':\'ERROR\',
            \'class\':\'logging.handlers.RotatingFileHandler\',
            \'filename\': \'log/error.log\',
            \'maxBytes\':1024*1024*5,
            \'backupCount\': 5,
            \'formatter\':\'standard\',
            },
        \'console\':{
            \'level\': \'DEBUG\',
            \'class\': \'logging.StreamHandler\',
            \'formatter\': \'standard\'
        },
        \'request_handler\': {
            \'level\':\'DEBUG\',
            \'class\':\'logging.handlers.RotatingFileHandler\',
            \'filename\': \'log/script.log\',
            \'maxBytes\': 1024*1024*5,
            \'backupCount\': 5,
            \'formatter\':\'standard\',
            },
        \'scprits_handler\': {
            \'level\':\'DEBUG\',
            \'class\':\'logging.handlers.RotatingFileHandler\',
            \'filename\':\'log/script.log\',
            \'maxBytes\': 1024*1024*5,
            \'backupCount\': 5,
            \'formatter\':\'standard\',
            }
    },
    \'loggers\': {
        \'django\': {
            \'handlers\': [\'default\', \'console\'],
            \'level\': \'DEBUG\',
            \'propagate\': False
        },
        \'django.request\': {
            \'handlers\': [\'request_handler\'],
            \'level\': \'DEBUG\',
            \'propagate\': False,
            },
        \'scripts\': {
            \'handlers\': [\'scprits_handler\'],
            \'level\': \'INFO\',
            \'propagate\': False
        },
        \'blog.views\': {
            \'handlers\': [\'default\', \'error\'],
            \'level\': \'DEBUG\',
            \'propagate\': True
        },
    }
}

 

主页配置

#主页配置
SITE_NAME = \'Python 博客\' #博客名称
SITE_DESC =\'专注python开发、java开发、全栈开发\'   #博客简介

 

上下文处理文件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\',
                \'blog.views.global_setting\' #上下文处理作用,

                            ],
        },
    },
]

 

view设置

from django.shortcuts import render
import logging
from django.conf import settings
# Create your views here.

logger = logging.getLogger(\'blog.views\')


def global_setting(request):
    return {
        \'SITE_NAME \': settings.SITE_NAME,
    \'SITE_DESC\' : settings.SITE_DESC
    }


def index(request):
    try:
        file= open(\'ss.txt\',\'r\')
    except Exception as e:
        logger.error(e)
    return render(request,\'index.html\',locals())

 

数据库设置

DATABASES = {
    \'default\': {
        \'ENGINE\': \'django.db.backends.mysql\',
        \'NAME\': \'blogdb\',
        \'USER\': \'root\',
        \'PASSWORD\': \'root\',
        \'HOST\': \'127.0.0.1\',
        \'PORT\': \'3306\',
    }
}
常用命令
python manage.py makemigrations
python manage.py createsuperuser
python manage.py migrate

 

index设置

{%  load staticfiles %}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{{ SITE_NAME }}</title>
<meta name="keywords" content="{{ SITE_NAME }}" />
<meta name="description" content="{{ SITE_DESC }}" />
<link href=\'{% static \'css/base.css\' %}\'  rel="stylesheet">
<link href=\'{% static \'css/index.css\'%}\' rel="stylesheet">
<script type="text/javascript" src=\'{% static \'js/jquery.min.js\'%}\'></script>
<script type="text/javascript" src=\'{% static \'js/sliders.js\'%}\'></script>
<!--[if lt IE 9]>
<script src="{% static \'js/modernizr.js"\'%}\'></script>
<![endif]-->
</head>
<body>
<header>
  <div class="logo">
      <h1> Python 博客 </h1>
      <p>{{ SITE_DESC }}</p>

 

app详细列表

 

 


 


 

以上是关于blog开发环境环境设置的主要内容,如果未能解决你的问题,请参考以下文章

[异常解决] Keil安装好nRF51822开发环境,运行DEMO报错:Error:“GPIOTE_CONFIG_NUM_OF_LOW_POWER_ENVENTS” is undefined(代码片段

如何为 UCMA 4.0 开发设置环境

vscode 开发微信小程序环境配置

设置和获取与执行环境相关的信息?

ubantu上配置开发环境

一步一步设置Joomla!开发环境