For this discussion I have a Django environment with an app.
Topic:
Namespace
Desc:
I’m using url namespace and so far no issues until i have 1 web page with more than 1 link to other pages.
Problem outline:
I load / display console.html page. This page is basically including the base_console_ap.html that will be only used within this app and that’s why it’s not in the outer project level templates folder. The console_app.html load fine. When I select the first link {% url 'console_app:console_ivanti' %}
it loads the console_ivanti.html page. When I select the 2nd link {% url 'console_app:console_msl' %}
it still only loads the 1st link. If I re-order the urls.py path lines it flips it. Will load the 2nd page only and not page 1.
from this:
path('console_app/', views.console_ivanti, name='console_ivanti'),
path('console_app/', views.console_msl, name='console_msl'),
to this:
path('console_app/', views.console_msl, name='console_msl'),
path('console_app/', views.console_ivanti, name='console_ivanti'),
This is the structure and content of files concerned.
<folder structure>
enoc_project
console_app
templates
console_app
console_msl.html
console_ivanti.html
console.html
base_console_ap.html
urls.py
views.py
urls.py
from django.urls import include, path, re_pat
from django.urls import reverse
from . import views
app_name = 'console_app'
urlpatterns = [
path('console_app/', views.console_ivanti, name='console_ivanti'),
path('console_app/', views.console_msl, name='console_msl'),
#path('console_app/', views.console_ivanti, name='console_ivanti'),
]
views.py
def console_msl(request):
return render(request,'console_app/console_msl.html')
def console_ivanti(request):
return render(request,'console_app/console_ivanti.html')
base_console_ap.html
<li><a class="dropdown-item" href="{% url 'console_app:console_ivanti' %}">Ivanti</a></li>
<li><a class="dropdown-item" href="{% url 'console_app:console_msl' %}">MSL - Master Server List</a></li>
console_msl.html
{% extends 'console_app/base_console_ap.html' %}
{% load static %}
<!doctype html>
<html lang="en">
<body>
{% block content %}
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<p>Console Master Server List</p>
</body>
</html>
{% endblock content %}
console_ivanti.html
{% extends 'console_app/base_console_ap.html' %}
{% load static %}
<!doctype html>
<html lang="en">
<body>
{% block content %}
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<p>Console Ivanti</p>
</body>
</html>
{% endblock content %}