URL redirections

Hello,

I’am having a Question about URL redirection:
In my project I have the following urls.py:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path(‘admin/’, admin.site.urls),
path(‘’, include(‘leden.urls’)),
]

I also created a App named leden with the following config:

from django.urls import path
from .views import Home, RegisterView

urlpatterns = [
path(‘’, Home, name=‘leden-home’),
path(‘register/’, RegisterView.as_view(), name=‘leden-register’),
]

In my app I configured added the following code:
from django.shortcuts import render, redirect
from django.contrib import messages
from django.views import View
from .forms import RegisterForm

Create your views here.

def Home(request):
return render(request, ‘leden/home.html’)

And in my app I created a templates\leden folder where my home.html is located. when i run the server and going to 127.0.0.1:8000 I am getting the following error:

Page not found (404)

Request Method: GET
Request URL: http://127.0.0.1:8000/leden/

Using the URLconf defined in website.urls, Django tried these URL patterns, in this order:

  1. admin/
  2. [name=‘leden-home’]
  3. register/ [name=‘leden-register’]

The current path, leden/, didn’t match any of these.

Hopefully you can help figuring out what Iam doing wrong

Thank’s in advance

Roel Knippen

path(‘’, include(‘leden.urls’)),

this must be root slash in root url as below.,

path(‘/’, include(‘leden.urls’)),

Hope it helps.

Side note: When posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted. (You can also use this with error messages, templates, etc)

You don’t have a path for leden.

No, actually it does not.

1 Like