Hello everyone. I’m currently working on a Django project and encountering an issue with template rendering. It’s not loading at all. I have conference app in my project. All apps are located in apps folder with one templates, in this templates there are templates with names of apps.
I have side navigation bar. When I click on ‘Conference Hall’ I face issue, template is not rendering
<li class="nav-item">
<a class="nav-link" href="{% url 'conference' %}">
<i class="ni ni-collection text-blue"></i>
<span class="nav-link-text">Conference Hall</span>
urls.py of conference app
#CONFERENCE URLS.PY
from django.urls import path
from apps.conference import views
urlpatterns = [
path('conference/', views.conference, name='conference')
# Other URL patterns for your app's views...
]
views.py of conference app
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
@login_required(login_url="/login/")
def conference(request):
return render(request, 'conference/conference.html')
settings.py of project
import os
from decouple import config
from unipath import Path
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = Path(__file__).parent
CORE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY', default='Sdhdsjqwi(2728_')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', default=True, cast=bool)
# load production server from .env
ALLOWED_HOSTS = ['localhost', '127.0.0.1', config('SERVER', default='127.0.0.1')]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#my apps
'apps.home',
'apps.authentication',
'apps.conference',
'apps.chat',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'core.urls'
LOGIN_REDIRECT_URL = "home" # Route defined in home/urls.py
LOGOUT_REDIRECT_URL = "home" # Route defined in home/urls.py
TEMPLATE_DIR = os.path.join(CORE_DIR, "apps/templates") # ROOT dir for templates
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'core.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ff',
'USER': 'root',
'PASSWORD': 'my_password',
'HOST': 'localhost',
'PORT': '3306',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'New York'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# SRC: https://devcenter.heroku.com/articles/django-assets
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_ROOT = os.path.join(CORE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(CORE_DIR, 'apps/static'),
)
core urls.py
from django.contrib import admin
from django.urls import path, include # add this
urlpatterns = [
path('admin/', admin.site.urls), # Django admin route
path("", include("apps.authentication.urls")), # Auth routes - login / register
path("", include("apps.home.urls")), # UI Kits Html files
# path('', include('apps.photogallery.urls')),
path('', include('apps.conference.urls')),
]
STRUCTURE OF TEMPLATES
error handler
{% extends 'layouts/base-fullscreen.html' %}
{% block title %} Error 404 {% endblock title %}
<!-- Specific CSS goes HERE -->
{% block stylesheets %}{% endblock stylesheets %}
{% block content %}
<!-- Page content -->
<div class="container mt--8 pb-5">
<div class="row justify-content-center">
<div class="col-lg-5 col-md-7">
<div class="card bg-secondary shadow border-0">
<div class="card-header bg-transparent pb-5">
<div class="text-muted text-center mt-2 mb-3">
Error 500
</div>
<div class="text-center mb-4">
Page does not exist - <a href="/">Main page</a>.
</div>
</div>
</div>
<div class="row mt-3">
<div class="col-6">
<a href="/" class="text-light"><small>Go to main page</small></a>
</div>
<div class="col-6 text-right">
<a target="_blank"
href="https://gf.kg/" class="text-light"><small>GF</small></a>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
<!-- Specific JS goes HERE -->
{% block javascripts %}{% endblock javascripts %}
May be I should change code in settings.py?
Thanks in advance!