Issue
I am new to django and started with a basic. The problem is while following a tutorial I created an account app that has a register page. For some reason whenever I am trying to go to my register page, django tells me that it doesn't match any of the paths.
below is the given code: accounts app url.py
from django.urls import path
from . import views
urlpatterns = [
path('register', views.register, name="register")
]
accounts app's views
from django.shortcuts import render
def register(request):
return render(request, 'register.html')
register.html is:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registeration</title>
</head>
<body>
<form action="register" method = "post">
{% csrf_token %}
<input type= "text" name="first_name" placeholder="First Name"><br>
<input type= "text" name="last_name" placeholder="Last Name"><br>
<input type= "text" name="username" placeholder="UserName"><br>
<input type= "text" name="password1" placeholder="Password"><br>
<input type= "text" name="password2" placeholder="Verify Password"><br>
<input type= "submit">
</form>
</head>
<body>
</body>
</html>
```
web_project urls.py
```
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path("", include('travello.urls')),
path('admin/', admin.site.urls),
path('accounts/', include('accounts.urls')),
]
urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
the error I am getting is given below:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/register.html
Using the URLconf defined in web_project.urls, Django tried these URL patterns, in this order:
[name='index']
admin/
accounts/ register [name='register']
^media/(?P<path>.*)$
The current path, accounts/register.html, didn’t match any of these.
You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
P.s: I know this question has been asked before but I tried everything still unable to understand where I am making a mistake.
Solution
You forgot to add /
to your URL
path('register/', views.register, name="register")
in settings.py
make:
TEMPLATES = [
{
...
'DIRS': ['templates'],
...
}
Answered By - Mohamed Hamza
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.