Use Express+mongodb to build multiplayer blog learning (2) Routing and templates

Source: Internet
Author: User


To modify the index.js routing rule:

varExpress = require (' Express ');varRouter =Express. Router ();/*GET home page.*/Router.get (‘/‘,function(req, res, next) {Res.render (' Index ', {title: ' home Page ' });}); Router.get ('/reg ',function(Req,res,next) {Res.render (' Reg ', {title: ' Register ' });}); Router.post ('/reg ',function(Req,res,next) {}); Router.get ('/login ',function(Req,res,next) {Res.render (' Login ', {title: ' Login ' });}); Router.post ('/reg ',function(Req,res,next) {}); Router.get ('/post ',function(Req,res,next) {Res.render (' Post ', {title: ' Publish ' });}); Router.post ('/post ',function(Req,res,next) {}); Router.get ('/logout ',function(Req,res,next) {}); Module.exports= Router;

2. Modify the Index.ejs view

<%-include header%> This is the home page <%-include footer%>

3. New Header.ejs

<! DOCTYPE html>

4. New Footer.ejs

        </article>    </body>

5, added Login.ejs Reg.ejs post.ejs

<%-include header%>    <form method= "POST" >         User name:<input type= "text" name= "name"/> <br/>         Password:<input type= "password" name= "password"/><br/> <input        type= "Submit" value= "Login"/>    </form><%-include footer%>
<%-include header%>    <form method= "POST" >         User name:<input type= "text" name= "name"/> <br/>         Password:<input type= "password" name= "password"/><br/>         Confirm Password: <input type= "Password" name= "Repassword"/><br/>         Email:<input type= "email" name= "email" /><br/>        <input type= "Submit" value= "register"/> </form><%-    include footer%>
<%-include header%>    <form method= "POST" >         title:<br/>        <input type= "text" Name= "title"/><br/>         Body:<br/>        <textarea name= "POST" rows= "cols=" > </textarea><br/>         <input type= "Submit" value= "Login"/>    </form><%-include footer% >

Now the browser can access the form page:

Use Express+mongodb to build multiplayer blog learning (2) Routing and templates

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.