3
3
3DOSES2021-01-27 17:57:56
Django
3DOSES, 2021-01-27 17:57:56

What is my mistake when using html?

I created a templates folder and in it I created a main folder where I placed the html file.
60117e2edd5a1652946002.png

Next, I made the path to views through render

from django.shortcuts import render
from django.http import HttpResponse


def index(request):
  return render(request, 'main/index.html')


def about(request):
  return HttpResponse("<h4>About</h4>")


And I wrote test text in index.html
<html>
    <p>Hi there!</p>
    <p>It works!</p>
</html>


As a result, it gives the following error in the console
(newdjango) C:\Users\iliab\OneDrive\Рабочий стол\projectdj\myfirst>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
January 27, 2021 - 18:51:04
Django version 3.1.5, using settings 'myfirst.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Internal Server Error: /
Traceback (most recent call last):
  File "C:\Users\iliab\OneDrive\Рабочий стол\projectdj\newdjango\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\iliab\OneDrive\Рабочий стол\projectdj\newdjango\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\iliab\OneDrive\Рабочий стол\projectdj\myfirst\main\views.py", line 6, in index
    return render(request, 'main/index.html')
  File "C:\Users\iliab\OneDrive\Рабочий стол\projectdj\newdjango\lib\site-packages\django\shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "C:\Users\iliab\OneDrive\Рабочий стол\projectdj\newdjango\lib\site-packages\django\template\loader.py", line 61, in render_to_string
    template = get_template(template_name, using=using)
  File "C:\Users\iliab\OneDrive\Рабочий стол\projectdj\newdjango\lib\site-packages\django\template\loader.py", line 19, in get_template
    raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: main/index.html
[27/Jan/2021 18:51:09] "GET / HTTP/1.1" 500 74982


Thanks in advance for your help <3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-01-27
@3DOSES

In settings.py main added to INSTALLED_APPS ?
If you are creating a new application via startapp , don't forget to add it to the INSTALLED_APPS list in the settings.py file

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question