H
H
hollanditkzn2017-10-19 18:08:04
Node.js
hollanditkzn, 2017-10-19 18:08:04

How to display pages in express?

I have such a problem, I seem to have done everything right, but for some reason I can’t display the page, it says that 404 error
All the path is something like
routes/
registration.js
views/
registration.pug
app.js
In the file routes/registration.js

let express = require('express');
let router = express.Router();

router.get('/registration', (req, res, next) => {
    res.render('registration', {title: 'Региcтрация'})
});

module.exports = router;

In the views/registration.pug template
extends layout

block content
    .container
        h1=title
        label(for='login') Имя пользователя
        input#login(type='text', name='login')
        label(for='password') Пароль
        input#password(type='text', name='password')
        button(class='btn waves-effect waves-light') Зарегистрировать пользователя

in app.js
let     registration = require('./routes/registration'),
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use('/registration', registration);

Yes, and I forgot to have index.pug, which translates to registration
extends layout

block content
  //p Welcome to #{title}
  .container
      h1= title
      form(method='post')
          .loginForm
              label(for='login') Логин
              br
              input#login(type='text', name='login')
          .passwordForm
                label(for='password') Пароль
                br
                input#password(type='password', name='password')
          button(class='btn waves-effect waves-light', type='Login') Войти
      a(href='/registration') Зарегестрироваться

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question