@3DOSES

В чем моя ошибка при использовании html?

Я создал папку templates и в ней создал папку main где разместил html файл.
60117e2edd5a1652946002.png

Далее я сделал путь в views через рендер
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>")


И написал в index.html тестовый текст
<html>
    <p>Hi there!</p>
    <p>It works!</p>
</html>


В итоге выдает такую ошибку в консоли
(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


Заранее спасибо за вашу помощь <3
  • Вопрос задан
  • 324 просмотра
Решения вопроса 1
SoreMix
@SoreMix
yellow
В settings.py main добавлено в INSTALLED_APPS?

Если создаете новое приложение через startapp - не забывайте добавить его в список INSTALLED_APPS в файле settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main',
]
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы