'Why my single page in Hugo returns a 404 HTTP error?

I am trying to create a site with Hugo, but I don't get how to add a single page to my website (posts are working fine).

Starting from a fresh install (v.0.27 64x for windows) and running the following command from my terminal:

> hugo new site soexample
> cd soexample
> git clone https://github.com/parsiya/Hugo-Octopress.git themes\octopress
> hugo new about.md
> echo "Please display me" >> content\about.md
> hugo serve -D -t octopress

I can see that my draft page is rendered from the output of the last command:

...
Built site for language en:
1 of 1 draft rendered
...

but when I try to access either http://localhost:1313/about/ or http://localhost:1313/about.html, the server (not the browser) returns a white page with:

404 page not found

What am I missing ?



Solution 1:[1]

In order to render standalone pages in Hugo you need to set the type to page and make sure you have a 'single' template in your layouts.

In the about.md front-matter set type = "page". In the layouts folder under _default folder make sure you have a single.html file.

That's it, the /about page now should render properly.

Solution 2:[2]

Possible duplicate, How to add a new hugo static page?

I already answer in that question, copy pasting here also.

I had a similar requirement, to add static page (aboutus in this case). Following steps did the trick,

  • Created an empty file content/aboutus/_index.md
  • Created aboutus.html page layouts/section/aboutus.html

Solution 3:[3]

I think the problem could be related to draft.

By default, the newly created content has draft: false, and hugo will exclude draft files by default.

You can change it to draft: true or use --buildDrafts option.

Solution 4:[4]

Just stumbled on here, it was drafts, but in my case the solution had an interesting wrinkle:

about/_index.md  (draft)
about/other.md  (not a draft)

Hugo ignores other.md when not building drafts, regardless of other.mds draft state. I'll leave it to the reader to decide if this is a bug or a feature.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jediz
Solution 2 Balkrishna
Solution 3 Shuo Feng
Solution 4 Simon Thum