使用express+mongoDB搭建多人博客 学习(2)路由与模板
修改index.js路由规则:
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: '主页' });
});
router.get('/reg',function(req,res,next){
res.render('reg', { title: '注册' });
});
router.post('/reg',function(req,res,next){
});
router.get('/login',function(req,res,next){
res.render('login', { title: '登录' });
});
router.post('/login',function(req,res,next){
});
router.get('/post',function(req,res,next){
res.render('post', { title: '发表' });
});
router.post('/post',function(req,res,next){
});
router.get('/logout',function(req,res,next){
});
module.exports = router;
2、修改index.ejs视图
<%- include header %>
这是主页
<%- include footer%>
3、新增header.ejs
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Blog</title>
<link rel="stylesheet" href="/stylesheets/style.css">
</head>
<body>
<header>
<h1><%= title %></h1>
</header>
<nav>
<span><a title="主页" href="/">home</a></span>
<span><a title="登录" href="/login">login</a></span>
<span><a title="注册" href="/reg">register</a></span>
</nav>
<article>
4、新增footer.ejs
</article>
</body>
</html>
5、新增login.ejs reg.ejs post.ejs
<%- include header %>
<form method="post">
用户名:<input type="text" name="name"/><br/>
密码:<input type="password" name="password"/><br/>
<input type="submit" value="登录"/>
</form>
<%- include footer %>
<%- include header %>
<form method="post">
用户名:<input type="text" name="name"/><br/>
密码:<input type="password" name="password"/><br/>
确认密码:<input type="password" name="repassword"/><br/>
邮箱:<input type="email" name="email"/><br/>
<input type="submit" value="注册"/>
</form>
<%- include footer %>
<%- include header %>
<form method="post">
标题:<br/>
<input type="text" name="title"/><br/>
正文:<br/>
<textarea name="post" rows="20" cols="100"></textarea><br/>
<input type="submit" value="发表"/>
</form>
<%- include footer %>
现在浏览器可以访问表单页面:

使用express+mongoDB搭建多人博客 学习(2)路由与模板的更多相关文章
- 使用express+mongoDB搭建多人博客 学习(6)发表文章
发表文章 1.在modules文件夹下新建post.js var mongodb=require("./db"); function Post(name,title,post){ ...
- 使用express+mongoDB搭建多人博客 学习(3)connect-flash和mongodb,表单注册
1.根目录下新建settings.js,存放数据库配置 module.exports={ cookieSecret:"myblog", db:"blog", h ...
- 使用express+mongoDB搭建多人博客 学习(5)权限控制
修改index.js如下: var express = require('express'); var router = express.Router(); var crypto=require('c ...
- 使用express+mongoDB搭建多人博客 学习(1) 安装blog工程
一.安装 1.安装express npm install -g expressnpm install -g express-generator 2.用ejs做模板,新建blog工程express -e ...
- 使用express+mongoDB搭建多人博客 学习(4)登录与登出
登录 修改index.ejs <%- include header %> <% if(locals.error){ %> <span><%= locals.e ...
- nodejs实战《一起学 Node.js》 使用 Express + MongoDB 搭建多人博客
GitHub: https://github.com/nswbmw/N-blog N-blog 使用 Express + MongoDB 搭建多人博客 开发环境 Node.js: 6.9.1 Mong ...
- 2015年12月12 Node.js实战(一)使用Express+MongoDB搭建多人博客
序,Node是基于V8引擎的服务器端脚本语言. 基础准备 Node.js: Express:本文用的是3.21.2版本,目前最新版本为4.13.3,Express4和Express3还是有较大区别,可 ...
- 第1章 Express MongoDB 搭建多人博客
学习环境 Node.js : 0.10.22 + Express : 3.4.4 + MongoDB : 2.4.8 + 快速开始 安装 Express express 是 Node.js 上最流行的 ...
- 基于react全家桶+antd-design+webpack2+node+express+mongodb开发的前后台博客系统
很久没更新博客,最近也有点忙,然后业余时间搞了一个比较完整基于react全家桶+antd-design+webpack2+node+express+mongodb开发的前后台博客系统的流程系统,希望对 ...
随机推荐
- 让tomcat启动时,自动加载你的项目
在tomcat-->conf-->serve.xml文件最后加上 <Context path="/atest" docBase="E:\Workspac ...
- 提高scroll性能
在DevTools中开始渲染,向下滑动一点点滚动条,然后停止滚动. 在结果中,注意frames总是在30ftps线上面,甚至都木有很接近69ftps线的(事实上帧执行的太缓慢以致于60ftps线在图上 ...
- PHP自定义网站根目录
1.打开httpd.conf配置文件(xampp下apache文件夹中的conf里) Ctrl + F 查找documentroot 找到结果 改好后保存,并重启apache
- luogu 3389 【模板】高斯消元
大概就是对每一行先找到最大的减小误差,然后代入消元 #include<iostream> #include<cstdio> #include<cstring> #i ...
- bzoj3680
$模拟退火$ $这种全局最优的问题用模拟退火$ $模拟退火就是每次向四周随机移动,移动的幅度和温度成正比,如果新的位置更优就接受,否则按一定概率接收,概率和温度成正比$ $最后稳定后再在最优解附近蹦跶 ...
- bzoj2687
整体二分+决策单调性 这个方法已经忘了... 决策单调性是指dp[i]由dp[1]->dp[i-1]更新,那么当dp[j]比dp[k]优且j>k时,对于i->n j都比k优 通过这个 ...
- Adventure Works 教程
多维建模(Adventure Works 教程) 欢迎使用 Analysis Services 教程. 本教程通过在所有示例中使用虚构公司 Adventure Works Cycles,说明如 ...
- Deques and Randomized Queues
1. 题目重述 完成三个程序,分别是双向队列,随机队列,和随机队列读取文本并输出k个数. 2. 分析 2.1 双向队列 题目的性能要求是,操作时间O(1),内存占用最大48n+192byte. 当使用 ...
- 使用httpClient下载网页
HttpCore 对HTTP协议客户端编程做了一些基本的封装.例如,格式化请求头和解析响应头.LineF ormatter用来格式化请求头信息,而实际的实现在BasicLineF ormatter 上 ...
- 1.1-1.3 HBase入门
一.HBASE入门 部分参考链接:https://www.cnblogs.com/steven-note/p/7209398.html 1.简介 HBase – Hadoop Database,是一个 ...