一. 创建一个名字为blog:django-admin startproject blog
cd 进入后,运行:python manage.py runserver
git add.
git commit -m 'Django'
git pull
二。配置setting
setting 配置 mysql redis, log
url 配置路径
1 mysql 本地配置:
mysql> create database blog charset=utf8;
mysql> create user caomei identified by '12345678';
mysql> grant all on blog.* to 'caomei'@'%';
mysql> flush privileges;
可能报错:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required:
https://blog.csdn.net/lvluobo/article/details/107850673
2安装redis教程:
https://www.runoob.com/note/36178
安装之后可能出现的问题:
https://blog.csdn.net/weixin_42039715/article/details/82118116
https://blog.csdn.net/n_fly/article/details/52692480
启动:
redis-server
配置:
https://www.cnblogs.com/yunlongaimeng/p/9788254.html
# 指明使用redis的0号数据库
3 配置log文件:
#url里面配置
import logging#1导入loging logger=logging.getLogger('django')#2获取日志器 def log(request): logger.info('info')#3使用日志器记录信息 return HttpResponse('aaaaaaaaaaaaaaaaaaaaa')
setting里面配置log:
1 创建logs文件
4 配置 :static:
设置静态资源的路径:
1创建static文件。
STATIC_URL = '/static/' #STATIC的url
STATICFILES_DIRS=[
os.path.join(BASE_DIR,'static'), #定位到static文件!!!
]