Django 建立工程连接数据库

views:界面
Models : 数据
Template: 模板层
防止: 修改变动不受影响。建立虚拟环境。

建立项目名称。

新建项目结构:template,负责数据可视化

manage.py 创建环境。
python manage.py startapp django 创建一个app

第一步:在setting.py中 添加站点 INSTALLD_APPS"DJANGO_WED"

静态的视图。

views.py 负责调配: index.html
urls.py 负责网址
在项目路径下添加static文件夹下面添加css,img 资源
加载静态文件标签: {% land static %}


第二章 分页符

第一步:上下文

render() 渲染 参数: request, 指定网页,x.html, context

替换: context {{}}

def index(request):
context = {
'title':'just a title',
'des': 'Just a description',
'score': '1.0'
}
return render(request,"index.html")

在models.py
添加数据库

from Mongoengine import *
connect('wbsite',host='127.0.0.1',port=27017)

class ArtiInfo(Document):
des = StringField() 取出字段
title = StringField()
tags = StringField()

meta = {"collection": 'arti_info'} //表名

for i in ArtiInfo.object:
print(i.title,i.des,i.score,i.tags)

第二部: 模板语言
第三步: 分页符

原文地址:https://www.cnblogs.com/countryboy666/p/11839547.html