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

余生长醉 提交于 2021-01-27 02:08:41

问题


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 ?


回答1:


The problem seems to come from the selected default theme that do not render single page outside of posts section. Themes can be a tricky point for beginners as hugo isn't shipped with default one and no official theme is recommended or supported (so beginners may have to choose randomly).

So the following commands worked for me:

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

The page http://localhost:1313/about/ is correctly rendered.




回答2:


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.




回答3:


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



回答4:


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.



来源:https://stackoverflow.com/questions/46216333/why-my-single-page-in-hugo-returns-a-404-http-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!