0

I have an app in django that has a webpage with buttons to travel to another page via a menu and 8 hrefs. When I travel to the first page and try to click on another, I will encounter a 404 error.

Page not found (404)
http://127.0.0.1:8000/index.html/contact 

Here is my url.py

urlpatterns = [
     path('index.html/', views.homepage),
     path('contact.html/', views.contact),
     path('about.html/', views.about),
]

Views as well

def customers(request):
    return render(request, 'customers.html')

def about(request):
    return render(request, 'about.html')

def contact(request):
    form_class = ContactForm
    return render(request, 'contact.html', {
        'form': form_class,
    })

Settings is unchanged. I believe that is all there is in making a URL path for a webpage.

I do not want http://127.0.0.1:8000/index.html/contact I want http://127.0.0.1:8000/index or http://127.0.0.1:8000/contact
How do I keep my URLs basic?

Sleepy-Z
  • 83
  • 1
  • 12

2 Answers2

0

Your urls.py should contain the URL patterns. These can be different from the name of the files you put in your templates/ directory. As such, your patterns should not have ".html" extensions if you want to access without the ".html" in the URLs:

urlpatterns = [
     path('index/', views.homepage),
     path('contact/', views.contact),
     path('about/', views.about),
]

When you click on some "Contact" link on the index page, you seem to build a URL relative to the index page, not the root of your site. In your templates, the href attribute of links should start with "/", e.g.:

<a href="/contact/">Contact</a>

instead of

<a href="contact/">Contact</a>
mimo
  • 2,469
  • 2
  • 28
  • 49
0

Just remove .html from the urls.py

urlpatterns = [
     path('index/', views.homepage),
     path('contact/', views.contact),
     path('about/', views.about),
]
Bibek Bhandari
  • 422
  • 1
  • 4
  • 15