_nav.html
{% load static %}
<nav class="navbar navbar-light navbar-expand-md bg-light align-content-center">
<a href="/" class="navbar-brand d-flex w-25 mr-auto"><img src="{% static 'edms/img/logo.png' %}" alt="logo"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar3">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100" id="collapsingNavbar3">
<ul class="navbar-nav w-100 justify-content-center">
<li class="nav-item {% if add_doc %}active{% endif %}">
<a class="nav-link" href="/add_doc">Добавить документ</a>
</li>
<li class="nav-item {% if contr %}active{% endif %}">
<a class="nav-link" href="/contr">Контрагенты</a>
</li>
<li class="nav-item {% if dep %}active{% endif %}">
<a class="nav-link" href="/dep">Исполнители</a>
</li>
<li class="nav-item {% if doc %}active{% endif %}">
<a class="nav-link" href="/doc">Документы</a>
</li>
</ul>
<div class="navbar-collapse collapse w-25" id="collapsingNavbar3">
<ul class="navbar-nav w-100 justify-content-center">
{% if request.user.is_authenticated %}
Добро пожаловать, {{ user.username }}
<li class="nav-item">
<a href="{% url 'logout' %}">Выход</a>
</li>
{% else %}
<li class="nav-item {% if login %}active{% endif %}">
<a class="nav-link" href="/login">Авторизация</a>
</li>
<li class="nav-item {% if register %}active{% endif %}">
<a class="nav-link" href="/register">Регистрация</a>
</li>
{% endif %}
</ul>
</div>
</div>
</nav>
Реализовано вот такое меню, при переходе на страницы "Контргент", "Документы" и "Исполнители" ссылки в меню подсвечиваются, а вот при переходе по ссылке "Добавить документ" пункт меню не подсвечивается, так же не подсвечиваются "Авторизация" и "Регистрация". В чем может быть причина? Заметил так же закономерность, что не выделяются те пункты меню, где отображаются формы.
base.html
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, instal-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;300&display=swap" rel="stylesheet">
<title>{% block title %}{{ title }}{% endblock %}</title>
</head>
<body>
{% include 'inc/_nav.html' %}
{% if messages %}
{% for message in messages %}
{% if message.tags == 'error' %}
<div class="alert alert-danger" role="alert">
{{ message }}
</div>
{% else %}
<div class="alert alert-{{ message.tags }}" role="alert">
{{ message }}
</div>
{% endif %}
{% endfor %}
{% endif %}
{% block content %}{% endblock %}
{% block doc %}{% endblock %}
{% block dep %}{% endblock %}
{% block contr %}{% endblock %}
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
add_doc.html
{% extends 'base.html' %}
{% block title %}
Добавление документа
{% endblock %}
{% block content %}
<h1 align="center">Добавление документа</h1>
<form method="post">
{% csrf_token %}
<div class="container justify-content-center col-3">
{{ form.as_p }}
</div>
<div class="form-group row justify-content-center">
<button type="submit" class="btn btn-primary btn-lg">Добавить документ</button>
</div>
</form>
{% endblock %}
forms.py
from django import forms
from .models import Doc
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.contrib.auth.models import User
class UserLoginForm(AuthenticationForm):
username = forms.CharField(label='Имя пользователя', widget=forms.TextInput(attrs={'class': 'form-control'}))
password = forms.CharField(label='Пароль', widget=forms.PasswordInput(attrs={'class': 'form-control'}))
class UserRegistrationForm(UserCreationForm):
username = forms.CharField(label='Имя пользователя', widget=forms.TextInput(attrs={'class': 'form-control'}))
password1 = forms.CharField(label='Пароль', widget=forms.PasswordInput(attrs={'class': 'form-control'}))
password2 = forms.CharField(label='Подтверждение пароля',
widget=forms.PasswordInput(attrs={'class': 'form-control'}))
email = forms.EmailField(label='E-mail', widget=forms.EmailInput(attrs={'class': 'form-control'}))
class Meta:
model = User
fields = ('username', 'email', 'password1', 'password2')
class DocForm(forms.ModelForm):
class Meta:
model = Doc
fields = ['number', 'title', 'id_contr', 'reg_surname', 'reg_name', 'reg_patronymic', 'id_executor', 'comment']
widgets = {
'number': forms.NumberInput(attrs={'class': 'form-control'}),
'title': forms.TextInput(attrs={'class': 'form-control'}),
'id_contr': forms.Select(attrs={'class': 'form-control'}),
'reg_surname': forms.TextInput(attrs={'class': 'form-control'}),
'reg_name': forms.TextInput(attrs={'class': 'form-control'}),
'reg_patronymic': forms.TextInput(attrs={'class': 'form-control'}),
'id_executor': forms.Select(attrs={'class': 'form-control'}),
'comment': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}),
}
urls.py
from django.urls import path
from .views import *
urlpatterns = [
path('register/', register),
path('login/', user_login, name='login'),
path('logout/', user_logout, name='logout'),
path('doc/', AllDoc.as_view(), name='doc'),
path('dep/', AllDep.as_view(), name='dep'),
path('contr/', AllContr.as_view(), name='contr'),
path('add_doc/', AddDoc.as_view(), name='add_doc'),
path('', Index.as_view(), name='index')
]