Skip to content Skip to sidebar Skip to footer

Using Fancy Html Templates

After I added a lots of thing to my blog I wanted to add a template but to do that it seemed like I need to override. So I created a new app that is exact replica of the first one.

Solution 1:

Okay, i'm not exactly sure where did you put your template "home.html" file so i made the assumption of you putting it in the 'static' file same with all the other assets (js/css folders)

So i basically made the template section in settings.py the following:

TEMPLATES = [
        {'DIRS': [os.path.join(BASE_DIR, 'static')],},]
    BASE_DIR = Path(__file__).resolve().parent.parent
    STATIC_URL = '/static/'STATICFILES_DIRS = [
       os.path.join(BASE_DIR, 'static'),
    ] 

then inside "home.html", i changed every single 'myblog' to '.' and it worked just fine.

Oh, since the Auto-generated template settings basically has a specific way of searching, provided at "https://docs.djangoproject.com/en/3.2/ref/settings/#std:setting-TEMPLATES"

So provided your current settings of static files

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
    ]

Your django settings tells it to look for static on the same folder that manage.py is located at, (The value of the BASE_DIR) So in your html, remove 'myblog/' so the engine looks for 'static/js, static/css' however if you want to keep "myblog", inside static file which must be in the same folder as manage.py, create 'myblog' and move all the folders (js, css..) inside it so your file path would look like

mainsite:app_nameanother_appmanage.pystatic:myblog:cssjs

Apologies for the terrible answer format.

Solution 2:

Edit your settings.py :- replace BASE_DIR = Path(__file__).resolve().parent.parent on the top of the file just after importing os.

try this in setttings.py:

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myblog',
]

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]

Post a Comment for "Using Fancy Html Templates"