# Hugo generates page on-the-fly but gives a 404 when stopped and restarted

**URL:** <https://discourse.gohugo.io/t/hugo-generates-page-on-the-fly-but-gives-a-404-when-stopped-and-restarted/45378>\
**Category:** support\
**Created:** [July 20, 2023, 6:20pm UTC](https://discourse.gohugo.io/t/hugo-generates-page-on-the-fly-but-gives-a-404-when-stopped-and-restarted/45378 "2023-07-20T18:20:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![punkish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/punkish/32/16136_2.png) [@punkish](https://discourse.gohugo.io/u/punkish)\
**Post date:** [July 20, 2023, 6:20pm UTC](https://discourse.gohugo.io/t/hugo-generates-page-on-the-fly-but-gives-a-404-when-stopped-and-restarted/45378/1 "2023-07-20T18:20:58Z")

</div>

I have the following directory structure:

```auto
$ cd content
$ tree
.
├── _index.md
├── about
│ ├── _index.md
│ ├── projects
│ │ ├── icedig
│ │ │ ├── img
│ │ │ │ └── icedig.png
│ │ │ └── index.md
│ │ ├── img
│ │ ├── index.md
│

```

Hugo generates pages for the following

- server/about/ → a list of all the “abouts” using `layouts/about/list.html`
- server/about/projects/ → a list of all the “projects” using `layouts/about/single.html`

but fails to generate

- server/about/projects/icedig/ → single page info about “icedig” project. I get a 404

Now here is where I am getting baffled. If, while `hugo server` is running, I change `icedig/index.md` to `icedig/_index.md` then hugo generates a page on-the-fly for `server/about/projects/icedig` using `layouts/about/list.html`. Then, if I stop and restart hugo, I again get a 404. However, now if I change the `icedig/_index.md` back to `icedig/index.md`, hugo generates a page on-the-fly for `server/about/projects/icedig` using `layouts/about/single.html`. Once again, when I stop and restart hugo, that page is no longer there and I get a 404.

So, what would I like? Well, I’d like to understand Hugo’s behavior so I can do the right thing. And, I would like to be able to get a page at `server/about/projects/icedig` (and all other entries under `projects` if they have an `index.md`)

I found a similar thread [Hugo renders page, restart server, returns 404. BUG?](https://discourse.gohugo.io/t/hugo-renders-page-restart-server-returns-404-bug/22646) but not quite.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [July 20, 2023, 6:45pm UTC](https://discourse.gohugo.io/t/hugo-generates-page-on-the-fly-but-gives-a-404-when-stopped-and-restarted/45378/2 "2023-07-20T18:45:13Z")

</div>

Your directory structure should be:

```plaintext
content/
├── about/
│ ├── projects/
│ │ ├── icedig/
│ │ │ ├── img/
│ │ │ │ └── icedig.png
│ │ │ └── index.md <-- icedig (page bundle)
│ │ └── _index.md <-- projects (section / branch bundle)
│ └── _index.md <-- about (section / branch bundle)
└── _index.md <-- home page

```

---

<div class="post-metadata">

**Author:** ![punkish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/punkish/32/16136_2.png) [@punkish](https://discourse.gohugo.io/u/punkish)\
**Post date:** [July 20, 2023, 7:00pm UTC](https://discourse.gohugo.io/t/hugo-generates-page-on-the-fly-but-gives-a-404-when-stopped-and-restarted/45378/3 "2023-07-20T19:00:48Z")

</div>

I already tried what you suggest, but I must be doing something wrong.

For one, if I change `projects/index.md` to `projects/_index.md` then an automatic entry for _projects_ is not generated in the `about/` listing. All other sections under `about` do get their own entry.

Of course, I can manually add an for _projects_ to `layouts/about/list.html` but it is not consistent in appearance with other automatically generated list items. And, it is in the wrong order, appearing at the top of the list (because, obviously, it is not a part of the automatically generated list).

~~And, in any case, how/where do I store a layout for all the individual projects? Each project entry in its own folder has a different name. I want a standardized layout for all the individual project entries.~~ My current _layouts_ folder looks like so. I am assuming `projects/single.html` will be used for each _project_ entry

```auto
$ cd layouts/about
$ tree
.
├── list.html
├── projects
│ ├── list.html
│ └── single.html

```

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [July 20, 2023, 7:05pm UTC](https://discourse.gohugo.io/t/hugo-generates-page-on-the-fly-but-gives-a-404-when-stopped-and-restarted/45378/4 "2023-07-20T19:05:23Z")

</div>

> [@punkish](#):
>
> but I must be doing something wrong

Then compare to this:

```plaintext
git clone --single-branch -b hugo-forum-topic-45378 https://github.com/jmooring/hugo-testing hugo-forum-topic-45378
cd hugo-forum-topic-45378
hugo server

```

If you need additional assistance, please post a link to the public repository for your project.

See [Requesting Help](https://discourse.gohugo.io/t/requesting-help/9132).

> Let us see your code
> 
> Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.
> 
> If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

---

<div class="post-metadata">

**Author:** ![punkish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/punkish/32/16136_2.png) [@punkish](https://discourse.gohugo.io/u/punkish)\
**Post date:** [July 20, 2023, 7:12pm UTC](https://discourse.gohugo.io/t/hugo-generates-page-on-the-fly-but-gives-a-404-when-stopped-and-restarted/45378/5 "2023-07-20T19:12:31Z")

</div>

> Then compare to this

well, that didn’t work. I got the following error

```auto
hugo-forum-topic-45378 git:(hugo-forum-topic-45378) hugo server
Start building sites …
hugo v0.111.3+extended darwin/arm64 BuildDate=unknown VendorInfo=macports
ERROR 2023/07/20 21:07:46 render of "section" failed: "/Users/punkish/Projects/hugo-forum-topic-45378/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/list.html:2:15: executing "_default/list.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2023/07/20 21:07:46 render of "section" failed: "/Users/punkish/Projects/hugo-forum-topic-45378/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/list.html:2:15: executing "_default/list.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2023/07/20 21:07:46 render of "page" failed: "/Users/punkish/Projects/hugo-forum-topic-45378/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/single.html:2:15: executing "_default/single.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
Error: Error building site: failed to render pages: render of "home" failed: "/Users/punkish/Projects/hugo-forum-topic-45378/layouts/_default/baseof.html:2:15": execute of template failed: template: _default/home.html:2:15: executing "_default/home.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
Built in 4 ms

```

> If you need additional assistance, please post a link to the public repository for your project.

ok thanks, I will make a public version of the repo and come back for help.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [July 20, 2023, 7:20pm UTC](https://discourse.gohugo.io/t/hugo-generates-page-on-the-fly-but-gives-a-404-when-stopped-and-restarted/45378/6 "2023-07-20T19:20:20Z")

</div>

> [@punkish](#):
>
> that didn’t work

I can see you’re running an older version. Current version is [v0.115.4](https://github.com/gohugoio/hugo/releases/tag/v0.115.4).

---

<div class="post-metadata">

**Author:** ![punkish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/punkish/32/16136_2.png) [@punkish](https://discourse.gohugo.io/u/punkish)\
**Post date:** [July 20, 2023, 7:25pm UTC](https://discourse.gohugo.io/t/hugo-generates-page-on-the-fly-but-gives-a-404-when-stopped-and-restarted/45378/7 "2023-07-20T19:25:49Z")

</div>

> I can see you’re running an older version. Current version is [v0.115.4](https://github.com/gohugoio/hugo/releases/tag/v0.115.4).

I upgraded and now I can run it successfully. Bloody hell! your example works (and how did you make one up so quickly? I can’t even tie my shoes so fast!).

Ok thanks, I will study your example and see if I can replicate it (and learn what it is that I am doing that is preventing my version to not work).

Many thanks for your (insanely) quick response.
