Я новичок с Джанго.Я следую учебному пособию здесь :
Мы только что добрались до части с шаблонами.Итак, у меня есть шаблон, base.html:
{% load static %}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{% block title %}Django Boards{% endblock %}</title>
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
</head>
<body>
<div class="container">
<ol class="breadcrumb my-4">
{% block breadcrumb %}
{% endblock %}
</ol>
{% block content %}
{% endblock %}
</div>
</body>
</html>
У меня есть домашняя страница, которая расширяет base.html:
{% extends base.html %}
{% block title %}Boards{% endblock %}
{% block breadcrumb %}
<li class="breadcrumb-item active">Boards</li>
{% endblock %}
{% block content %}
<table class="table">
<thead class="thead-inverse">
<tr>
<th>Board</th>
<th>Posts</th>
<th>Topics</th>
<th>Last Post</th>
</tr>
</thead>
<tbody>
{% for board in boards %}
<tr>
<td>
<a href="{% url 'board_topics' board.pk %}">{{ board.name }}</a>
<small class="text-muted d-block">{{ board.description }}</small>
</td>
<td class="align-middle">0</td>
<td class="align-middle">0</td>
<td></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
У меня есть страница с именем themes.html, которая не(пока) расширяем base.html:
{% load static %}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{ board.name }}</title>
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
</head>
<body>
<div class="container">
<ol class="breadcrumb my-4">
<li class="breadcrumb-item"><a href="{% url 'home' %}">Boards</a></li>
<li class="breadcrumb-item active">{{ board.name }}</li>
</ol>
</div>
</body>
</html>
И у меня есть тестовая страница tests.py:
# from django.test import TestCase
# Create your tests here.
from django.urls import reverse
from django.urls import resolve
from django.test import TestCase
from .views import home, board_topics
from .models import Board
class HomeTests(TestCase):
def setUp(self):
self.board = Board.objects.create(name='Django', description='Djano Board')
url = reverse('home')
self.response = self.client.get(url)
def test_home_view_status_code(self):
self.assertEquals(self.response.status_code, 200)
def test_home_url_resolves_home_view(self):
view = resolve('/')
self.assertEquals(view.func, home)
def test_home_view_contains_link_to_topics_page(self):
board_topics_url = reverse('board_topics', kwargs={'pk': self.board.pk})
self.assertContains(self.response, 'href="{0}"'.format(board_topics_url))
class BoardTopicsTests(TestCase):
def setUp(self):
Board.objects.create(name='Django', description='Django board.')
def test_board_topics_view_success_status_code(self):
url = reverse('board_topics', kwargs={'pk': 1})
response = self.client.get(url)
self.assertEquals(response.status_code, 200)
def test_board_topics_view_not_found_status_code(self):
url = reverse('board_topics', kwargs={'pk': 99})
response = self.client.get(url)
self.assertEquals(response.status_code, 404)
def test_board_topics_url_resolves_board_topics_view(self):
view = resolve('/boards/1/')
self.assertEquals(view.func, board_topics)
def test_board_topics_view_contains_link_back_to_homepage(self):
board_topics_url = reverse('board_topics', kwargs={'pk':1})
response = self.client.get(board_topics_url)
homepage_url = reverse('home')
self.assertContains(response, 'href="{0}"'.format(homepage_url))
Когда я иду в командную строку и запускаю тест, я получаюэти сообщения об ошибках:
(venv_two) C:\Inetpub\wwwroot\myproject2\myproject2>python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
....EEE
======================================================================
ERROR: test_home_url_resolves_home_view (boards.tests.HomeTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Inetpub\wwwroot\myproject2\myproject2\boards\tests.py", line 14, in s
etUp
self.response = self.client.get(url)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 527, in get
response = super().get(path, data=data, secure=secure, **extra)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 339, in get
**extra,
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 414, in generic
return self.request(**r)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 495, in request
raise exc_value
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\core\han
dlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\core\han
dlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\core\han
dlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Inetpub\wwwroot\myproject2\myproject2\boards\views.py", line 9, in ho
me
return render(request, 'home.html', {'boards': boards})
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\shortcut
s.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=usi
ng)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\loader.py", line 62, in render_to_string
return template.render(context, request)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\base.py", line 171, in render
return self._render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\uti
ls.py", line 96, in instrumented_test_render
return self.nodelist.render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\loader_tags.py", line 127, in render
compiled_parent = self.get_parent(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\loader_tags.py", line 117, in get_parent
raise TemplateSyntaxError(error_msg)
django.template.exceptions.TemplateSyntaxError: Invalid template name in 'extend
s' tag: ''. Got this from the 'base.html' variable.
======================================================================
ERROR: test_home_view_contains_link_to_topics_page (boards.tests.HomeTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Inetpub\wwwroot\myproject2\myproject2\boards\tests.py", line 14, in s
etUp
self.response = self.client.get(url)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 527, in get
response = super().get(path, data=data, secure=secure, **extra)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 339, in get
**extra,
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 414, in generic
return self.request(**r)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 495, in request
raise exc_value
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\core\han
dlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\core\han
dlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\core\han
dlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Inetpub\wwwroot\myproject2\myproject2\boards\views.py", line 9, in ho
me
return render(request, 'home.html', {'boards': boards})
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\shortcut
s.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=usi
ng)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\loader.py", line 62, in render_to_string
return template.render(context, request)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\base.py", line 171, in render
return self._render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\uti
ls.py", line 96, in instrumented_test_render
return self.nodelist.render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\loader_tags.py", line 127, in render
compiled_parent = self.get_parent(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\loader_tags.py", line 117, in get_parent
raise TemplateSyntaxError(error_msg)
django.template.exceptions.TemplateSyntaxError: Invalid template name in 'extend
s' tag: ''. Got this from the 'base.html' variable.
======================================================================
ERROR: test_home_view_status_code (boards.tests.HomeTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Inetpub\wwwroot\myproject2\myproject2\boards\tests.py", line 14, in s
etUp
self.response = self.client.get(url)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 527, in get
response = super().get(path, data=data, secure=secure, **extra)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 339, in get
**extra,
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 414, in generic
return self.request(**r)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\cli
ent.py", line 495, in request
raise exc_value
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\core\han
dlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\core\han
dlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\core\han
dlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Inetpub\wwwroot\myproject2\myproject2\boards\views.py", line 9, in ho
me
return render(request, 'home.html', {'boards': boards})
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\shortcut
s.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=usi
ng)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\loader.py", line 62, in render_to_string
return template.render(context, request)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\base.py", line 171, in render
return self._render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\test\uti
ls.py", line 96, in instrumented_test_render
return self.nodelist.render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\loader_tags.py", line 127, in render
compiled_parent = self.get_parent(context)
File "C:\Inetpub\wwwroot\myproject2\venv_two\lib\site-packages\django\template
\loader_tags.py", line 117, in get_parent
raise TemplateSyntaxError(error_msg)
django.template.exceptions.TemplateSyntaxError: Invalid template name in 'extend
s' tag: ''. Got this from the 'base.html' variable.
----------------------------------------------------------------------
Ran 7 tests in 0.065s
FAILED (errors=3)
Destroying test database for alias 'default'...
Может кто-нибудь сказать мне, что означают эти ошибки, пожалуйста?Я думал, что точно следовал инструкциям в руководстве ...