I am working on a web-app using Django and everything is going well but there are two problems that I have been struggling with for the past week:
Problem 1: Within my project I have an app called User and it has the following structure:
User
>templates
>User
>Layout.html
>Home.html
>static
>css
>User
>Layout.css
>Home.css
I want to have the same header and left side menu across all my pages and here is how I went about it.
Layout.html
{% load static %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="{% static 'User/css/Layout.css' %}">
{% block head %}
{% block title %}
{% endblock %}
{% block references %}
{% endblock %}
{% endblock %}
</head>
<body>
<header class="uppermenu">
</header>
<div class="leftsidemenu">
</div>
<div class="content">
{% block content %}
{% endblock %}
</div>
</body>
</html>
Home.html
{% extends "User/Layout.html" %}
{% load static %}
{% block head %}
{% block title %}
<title>Home</title>
{% endblock %}
{% block references %}
<link rel="stylesheet" href="{% static 'User/css/Home.css' %}">
{% endblock %}
{% endblock %}
{% block content %}
<!--Each page is going to have different content but the left side menu
and the header should remain the same -->
{% endblock %}
When extending Layout.html in Home.html, I want to add Home.css and not sure where to put it. Where should I insert my stylesheets in Layout.html and Home.html? Should they go in the "head", {% block references %}, {% block content %} or where? What is the best practice?
2) Problem 2 - (the annoying one)
I type "python manage.py runserver" and constantly reload pages when I make changes in my templates and static files to see how they look. I can see changes in Html files taking place immediately, whereas it takes about 1 hour (sometimes longer) for CSS changes to take place. It is so weird and annoying because it is slowing me down significantly.
For example:
If I change <p1>Hello</p> to <p1>Bye</p> in Home.html and reload the
page, I could see the changes immediately and "Hello" changes to "Bye"
as it is supposed to be.
But if I change p1 {color: red}; to p1 {color: green} in my Home.css
then the changes take place about 1 hour later (didn't really set up a
timer but it takes so long).
I normally use Chrome but tried Safari and the result is the same. Could somebody help me out with these issues please? The second one concerns me more because I have no clue why it is happening.
import os
SECRET_KEY = 'whatever'
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'Application',
'Home',
'Login',
'User',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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 = 'Agent_WebApp.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'Agent_WebApp.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'AAA',
'USER': 'root',
'PASSWORD': 'AAA',
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME':
'django.contrib.auth.password_validation.UserAttribute
SimilarityValidator',
},
{
'NAME':
'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME':
'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME':
'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
EDIT: I am still in the development stage and my website did not go live yet