moardee
moardee

Reputation: 43

Pug template can't find CSS

I looked and it seems like this problem is usually related to a typo, however, I've checked mine a bunch of times and don't see that. The location where the console says it's looking is exactly where it should be:

html(lang="en")
  head
    link(rel='stylesheet', href='/stylesheets/style.css')
  body
    div#card
      h4 Your Moon Story!
      p#story #{moon_story}

in my index.js

// express set-up
app.set('view engine', 'pug')
app.set('port', (process.env.PORT || 5000));
app.use(express.static('/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressValidator()); // Add this after the bodyParser middlewares!

style.css is the name of my file, and /stylesheets is where it's at. It's looking at localhost:5000/stylesheets/style.css, which is exactly where it should be. Why is my CSS file not being found?

edit : moved it into public folder, its saying its not there still, even though I updated the path

Upvotes: 1

Views: 2538

Answers (2)

Arif Khan Khaishagi
Arif Khan Khaishagi

Reputation: 71

Remember to use indentation while using pug, i wasted 2 hours due to incorrect indentation.

Upvotes: 0

Riccardo Persiani
Riccardo Persiani

Reputation: 732

If you put the style.css file in the same folder of the .pug file, this should work:

doctype html
html(lang='en')
  head
    title Example
    style
      // Custom styles for this template
      include ../css/style.css

You can navigate into other folders using ../

example

Upvotes: 2

Related Questions