Hi Everyone,
I am currently working on a website. Up in the Navigation bar are several links
like “Home” “Contact” etc. One of my links is called “Teilnehmerliste”.
If I now click on “Teilnehmerliste” in the navigation bar, at first I get to my page successfully. But if I then want to click another link, Django doubles my path. For example, when I click “Contact”, Django calls the following link:
“WEBSITENAME/teilnehmerliste/contact” instead of “WEBSITENAME/contact”. And from then on nothing works anymore (Page not found). My HTML file for the link (Teilnehmerliste) is called “teilnehmerliste.html” and is located in the subfolder “teilnehmerliste” which in turn is in the “templates” folder. And the app folder is called “manage_teilnehmerlisteliste_app”.
My current configurations look like this:
urls.py (from the project folder):
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('teilnehmerliste/', include('manage_teilnehmerliste_app.urls')),
]
urls.py (from the app folder):
from django.urls import path
from . import views
urlpatterns = [
path('', views.teilnehmerliste, name='teilnehmerliste'),
views.py (from the app folder):
from django.shortcuts import render, redirect
from .models import ManageTeilnehmerListe
# Create your views here.
def teilnehmerliste (request):
context = ManageTeilnehmerListe.objects.all()
if request.method == 'POST':
new_participant = ManageTeilnehmerListe(
title = request.POST['title']
)
new_participant.save()
return redirect('/teilnehmerliste')
return render(request, 'teilnehmerliste/teilnehmerliste.html', {'contexts': context})
settings.py Datei:
TEMPLATES = [
{
...
'DIRS': [BASE_DIR/'templates'],
...
]
INSTALLED_APPS = [
...
'manage_teilnehmerliste_app',
...
]
models.py (aus dem App-Ordner):
from django.db import models
class ManageTeilnehmerListe(models.Model):
title = models.CharField(max_length=50)
def __str__(self):
return self.title
PS: By the way, I’ve already looked at many sites that deal with the problem.
Where is the mistake?