За последние 24 часа нас посетили 20336 программистов и 1006 роботов. Сейчас ищет 361 программист ...

node.js pug ошибка

Тема в разделе "JavaScript и AJAX", создана пользователем riaron, 8 сен 2020.

  1. riaron

    riaron Активный пользователь

    С нами с:
    1 окт 2014
    Сообщения:
    247
    Симпатии:
    4
    node.js pug при вводе неправильного расположения фото показывает что неправильно при правильном ничего не показывает хотя в исходном коде картинка есть
    Вот код:
    Код (Javascript):
    1. var express = require('express');
    2. var mysql = require('mysql');
    3. const fileUpload = require('express-fileupload');
    4. var app = express();
    5. const bodyParser = require("body-parser");
    6. app.use(fileUpload());
    7. app.use('/smart', express.static(__dirname + '/files/sphoto/'));
    8. ///
    9. ///    Create connection to MySQL database server.
    10. ///
    11. function getMySQLConnection() {
    12.     return mysql.createConnection({
    13.       host     : 'localhost',
    14.       user     : 'root',
    15.       password : '',
    16.       database : 'elektronika'
    17.     });
    18. }
    19.  
    20. app.set('view engine', 'pug');
    21.  
    22. const urlencodedParser = bodyParser.urlencoded({extended: false});
    23. app.get('/smart', function(req, res) {
    24.     var smartphopneList = [];
    25.  
    26.     // Connect to MySQL database.
    27.     var connection = getMySQLConnection();
    28.     connection.connect();
    29.  
    30.     // Do the query to get data.
    31.     connection.query('SELECT `id`,`prod`,`name`,`sim`,`display`,`razresh`,`acum`,`proc`,`oper`,`sd`,`cam`,`gps`,`description`,`giroscope`,`payment`,`photo` FROM `smartphone` ', function(err, rows, fields) {
    32.           if (err) {
    33.               res.status(500).json({"status_code": 500,"status_message": "internal server error"});
    34.           } else {
    35.               // Loop check on each row
    36.               for (var i = 0; i < rows.length; i++) {
    37.  
    38.                   // Create an object to save current row's data
    39.                   var smartphopne = {
    40.                       'id':rows[i].id,
    41.                       'prod':rows[i].prod,
    42.                       'name':rows[i].name,
    43.                       'photo':rows[i].photo
    44.                   }
    45.                   // Add object into array
    46.                   smartphopneList.push(smartphopne);
    47.           }
    48.  
    49.           // Render index.pug page using array
    50.           res.render('index', {"smartphopneList": smartphopneList});
    51.           }
    52.     });
    53.  
    54.     // Close the MySQL connection
    55.     connection.end();
    56.    
    57. });
    58. app.listen(3000, function () {
    59.     console.log('listening on port', 3000);
    60. });
    Код (Text):
    1. html
    2.     head
    3.         title= 'Smartphones'
    4.         style
    5.             include style.css
    6.             include bootstrap.css
    7.  
    8.     body
    9.         h1= 'Smartphones'
    10.         for smart in smartphopneList
    11.             div= "id" + smart.id
    12.             img(src=''+smart.photo height='200px' width='200px')
    13.             div= "Производитель: " + smart.prod
    14.             div='Модель: ' + smart.name
    15.