So I have urls to redirect the user to certain pages (form and home). I have one which you can click at the top of the home page which successfully redirects you to the form page and I have the same system to bring you back to the home page from the form page except it doesnt seem to work and displays an error. Error Image
Here is my home html file which works :
<div >
<a href="/form"> </a>
</div>
Here is my form file which doesnt work :
<div >
<a href="/home"> </a>
</div>
Here is my views file :
def home(request):
litinfo = info.objects.all()
return render(request, 'home.html', {'litinfo': litinfo})
def form(request):
return render(request, 'form.html')
And finally here is my urls.py file :
urlpatterns = [
path('', views.home, name='home'),
path('form', views.form, name='form'),
]
Thanks in advance for any solutions, im new to django and just not too sure on how to fix this issue.
Edit : I've figured out that when I click on the URL in the form page it sends me to "http://(Numbers, not sure if confidential)/home" instead of "http://(Numbers, not sure if confidential)" which means it doesnt bring me back to the main page.
CodePudding user response:
You don't have a path for /home
in your ulrpatterns. Your error message says page not found (404) which means, it tried your to get the data in the path but the path doesn't exist.
Two ways to fix this:
- In the
form.html
file change:
<div >
<a href="/"> </a>
</div>
- In the urls.py file change:
urlpatterns = [
path('', views.home, name='home'),
path('form', views.form, name='form'),
path('home/', views.home, name='home'),
]