0

Edited question for clarity.

In my application, let's say I'm on some url as follows: http://127.0.0.1:8000/blog/ and on that page I have in my HTML:

<a href="#top">Back to top</a>

When I hover over that link, the URL says: http://127.0.0.1:8000/#top, and not http://127.0.0.1:8000/blog/#top, as I'd expect.

What's going on here? How do I fix this? Let me know if anything else is required.

Here's the summary of my HTML:

<!DOCTYPE html>
<head>
  <title>...</title>
  <base href="/">
  <!-- JQuery, Bootstrap, Bootstrap Javascript stuff included here -->
</head>
<body>
  <header>
    <!-- header stuff from Bootstrap -->
  </header>

  <section id="top">
    <!-- page-based contents here -->
  </section>

  <footer>
    <!-- Dead simple one-line footer -->
  </footer>
</body>
</html>
Mephoros
  • 1,617
  • 14
  • 28
  • 1
    Is is possible to have a look at your template/your view code? – Jivan Dec 16 '14 at 01:40
  • 2
    Have you clicked it and verified that it works? Are you using JavaScript at all? Can we see the portion of the HTML that the element with the id `top` is in? This is almost definitely not a django-related problem. It's likely something to do with your HTML. – Jamie Counsell Dec 16 '14 at 02:51
  • @JamieCounsell - Ahh I see where my problem is. I had a `` tag in my header. I wouldn't have thought to look there otherwise. Thanks for the nudge in the right direction. – Mephoros Dec 16 '14 at 02:59
  • Keep in mind also that it is often best to use `name='top'` instead of (or as well as) `id='top'`. Glad i could help! – Jamie Counsell Dec 16 '14 at 03:01
  • @JamieCounsell - Why is it recommended to use `name` vs `id`? Do you have any links to a relevant discussion? I've always wondered about the nuances between using one of the two. The only difference I (think) I know is that `id` works for CSS. – Mephoros Dec 16 '14 at 03:03
  • You're right that `id` works for CSS, but in templating it is very easily to accidentally have two elements with the same `id`. Although this is not correct, it is often overlooked so long as the CSS isn't affected (especially in complex template systems with many files). `name` ensures that we always reference the element we're looking for, and gives us the control to modify it independently of our CSS `id` selector. – Jamie Counsell Dec 16 '14 at 03:05
  • This might help! http://stackoverflow.com/questions/7470268/html-input-name-vs-id – Jamie Counsell Dec 16 '14 at 03:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/66952/discussion-between-mephoros-and-jamie-counsell). – Mephoros Dec 16 '14 at 03:08

1 Answers1

1

I had a <base href="/"> tag in my HTML header that was resolving the hash to http://127.0.0.1:8000/# instead of the proper location.

Mephoros
  • 1,617
  • 14
  • 28