Thursday, July 9, 2020

Dance Website Using Pug and Node js(For Backened)

Dance Website

Pug code ( generally pug is a template engine used in place of html , because it make the scripting easier as compared to html)

base.pug;

doctype html
html
  head
    title Pratik Dance Website
    block scripts
      script(src='../static/script.js')
    block style
      style
        include ../static/style.css
  body
    nav#navbar
        #logo
            img(src="/static/2.png"alt="")
        ul
            li #[a(href='/') Home]
            li #[a(href='/') About Us ]
            li #[a(href='/') Services]
            li #[a(href='/contact') Contact Info]
    block content
    block foot


      home.pug:

extends base.pug

block scripts
  script(src='../static/script.js')
block style
  style
    include ../static/style.css 
    include ../static/response.css 

block content
    

    section#introSection
        div Welcome to My Dance Academy
        .small Eat sleep Dance Repeat
    
    section#missionSection
        h2 Our Mission
        .mission
            .card
                h3 Dance perfection
                .card-box
                    .card-img
                        img(src="/static/card1.jpg"alt="")
                        p we will train in your best way
            .card
                h3 Removing your best dancer
                .card-box
                    .card-img
                        img(src="/static/logo1.png"alt="")
                        p we will train in your best way
            .card
                h3 Versatile Dancer
                .card-box
                    .card-img
                        img(src="/static/card2.png"alt="")
                        p we will train in your best way
    
    section#sponsorSection
        h2 Our Sponsors
        #sponsors
            img(src="/static/logo.jpg"alt="")
            img(src="/static/logo2.png"alt="")
            img(src="/static/logo3.jpg"alt="")

    footer#footer
        | this is footer

contact.pug:

extends base.pug

block scripts
  script(src='../static/script.js')
block style
  style
    include ../static/contact.css
    include ../static/style.css 
block content
  h3 Contact Us
  form(action="/contact"method="post")
    input(type="text"class="myInput",name="name",placeholder="enter your name")
    input(type="number"class="myInput",name="number",placeholder="enter your number")
    input(type="number"class="myInput",name="age",placeholder="enter your age")
    textarea(name="address",class="myInput"cols="30"rows="10",placeholder="Give your description")
    button(class="btn")
      | Submit

style.css
#navbar ul{
    displayflex;
    flex-directionrow;
    justify-contentcenter;
}

#navbar li{
    list-stylenone;

}

#logo{
    displayinline-block;
    /* align-items: center; */
    height40px;
}
#navbar #logo img{
    /* display: flex; */
    /* align-items: center; */
    height40px
}

@import url('https://fonts.googleapis.com/css2?family=Baloo+Bhaina+2&display=swap');

*{
    margin0px;
    box-sizingborder-box;
    padding0px;
    font-family'Baloo Bhaina 2'cursive;
}

#navbar{
    display:flex ;
    background-colorrgb(2304646);
    padding10px;
    font-size22px;
    font-family'Baloo Bhaina 2'cursive;
    positionsticky;
    
    
}
#navbar li a{
    text-decorationnone;
    padding10px 30px;
    colorwhite;
}

#navbar li a:hover{
    colorblack;
}

#introSection{
    displayflex;
    justify-contentcenter;
    align-itemscenter;
    font-family'Baloo Bhaina 2'cursive;
    backgroundurl('/static/dance2.jpg'center center/cover no-repeat;
    height600px;
    /* background-color: red; */
    colorwhite;
    font-size35px;
    flex-directioncolumn;
    padding-bottom40px;

}

.small{
    font-size1.3rem;
}

#missionSection{
    height330px;
    displayblock;
    width100%;
    marginauto;
    /* display: flex;
    justify-content: center;
    align-items: center; */
}
#missionSection .mission{
    height300px;
    /* width: 80%; */
    displayflex;
    justify-contentcenter;
    align-itemscenter;
}

#missionSection h2{
    text-aligncenter;
    padding5px;

}

.card{
    border2px solid black;
    border-radius15px;
    width30%;
    height70%;
    margin10px;
    displayinline-block;
    background-colorlemonchiffon;

}
.card h3{
    text-aligncenter;
    /* text-align: center; */
    margin10px;

}

.card-box{
    displayflex;
    justify-contentcenter;
    align-itemscenter;
    heightinherit;
}

.card-img{
    height100px
    
}

.card-img img{
    height100px
}
#sponsorSection{
    height300px;
    background-colorwhite;
    
}

#sponsorSection h2{
    text-aligncenter;
    padding5px;
    background-colorwheat;

}

#sponsors{
    displayflex;
    align-itemscenter;
    justify-contentcenter;
    padding-top20px;
}

#sponsors img{
    margin20px;
    padding1px;
    height150px;
    border2px solid;
    border-radius10px;
}
#footer{
    height100px;
    background-colorblack;

}

app.js:(This is backened file that is used to surf web and connect with
mongo db database and it is written in node js)
const express = require('express');
const app = express();
const path=require('path');
const fs = require('fs');
const port = 80;
const bodyparser = require('body-parser');
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/contactDance', {useNewUrlParser: true});

var db = mongoose.connection;
db.on('error'console.error.bind(console'connection error:'));
db.once('open'function() {
  // we're connected!
  console.log('connection established');
});

var contactSchema = new mongoose.Schema({
    name: String,
    number : String,
    age: String,
    description :String
  });

  var contact = mongoose.model('contact'contactSchema);

  




app.use('/static',express.static('static'));//for serving static files
app.use(express.urlencoded());


app.set('view engine','pug');//set the template engine as pug
app.set('views',path.join(__dirname,'views'));//set the views directory


app.get('/',(req,res)=>{
    const params={}
    res.status(200).render('home.pug',params);
})

app.get('/contact',(req,res)=>{
    res.render('contact.pug')
})
app.post('/contact',(req,res)=>{
    var myData = new contact(req.body);
    myData.save().then(()=>{
        res.send('this item has been saved to the database');
    }).catch(()=>{
        res.status(400).send('data not saved to the database')
    })
    // res.render('contact.pug')
})


app.listen(port,()=>{
    console.log("the application is running on port 80");

})
  



No comments:

Post a Comment