0
votes

Ive been trying to create a blog with django using my phone nd so far until yesterday it has been a success. I was creating my home page yesterday and when I run python manage.py runserver it returns a template not found error. What can be the issue.

This is my views.py

'''

from django.shortcuts import render

Create your views here.

def home(request):

   returnrender(request,'newfile.html')

'''

This is my urls.py

'''

from django.urls import path from . import views

urlpatterns = [

path('', views.home, name="homepage"),

]

'''

This is my settings.py

'''

"""

Django settings for myproject project.

Generated by 'django-admin startproject' using Django 3.2.7.

For more information on this file, see https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see https://docs.djangoproject.com/en/3.2/ref/settings/ """

import os

from pathlib import Path

Build paths inside the project like this: BASE_DIR / 'subdir'.

BASE_DIR = Path(file).resolve().parent.parent

Quick-start development settings - unsuitable for production

See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

SECURITY WARNING: keep the secret key used in production secret!

SECRET_KEY = 'django-insecure-@o12m78t3=13)@m-o^-ejlp@g!-0gz64fiwx%+raw753+=g2)r'

SECURITY WARNING: don't run with debug turned on in production!

DEBUG = True

ALLOWED_HOSTS = []

Application definition

INSTALLED_APPS =

[

'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',

]

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 = 'myproject.urls'

TEMPLATES = [

{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR,  'templates')],
    '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',
        ],
    },
},

]

'''

I made sure to avoid any spelling error or indentation error. What can be the problem

1

1 Answers

0
votes

First you should not post your secret key here.

Than you do have a a spelling error in def home(request):

returnrender(request,'newfile.html')

If thats correct on your local project:

What is the path to your templatefile ? It should be: myapp/template/myapp/home.html