B
B
BotaniQ_Q2017-08-19 19:39:23
Django
BotaniQ_Q, 2017-08-19 19:39:23

Template inheritance in Django?

Ok, I have a Blog project with an Article application inside it. In Article
I have a templates folder, this folder contains articles.html, with the following content:

{% extends to 'main.html'%}

{% block articles %}

{% for article in articles %}
<h1><a href="/articles/get/{{article.id}}">{{article.article_title}}</a></h1>
<h2>{{article.article_text}}</h2>
<h3>Дата публикации:{{article.article_date}}</h3>
<h4>Лайков:{{article.article_likes}}</h4>
<hr/>
{% endfor %}
{% endblock %}

It means that this file is embedded in the main.html file, which is located in the Blog / templates folder, that is, in addition to the fact that there is such a folder in Article, I created it in Blog,
here is the content of views.py, the Article application
from django.shortcuts import  render
from django.shortcuts  import render_to_response
from django.http.response import HttpResponse
from article.models import Article, Comments


def articles(reguest):
  return  render_to_response('articles.html', {'articles': Article.objects.all()})

def article (reguest, article_id=1):
  return  render_to_response('article.html', {'article': Article.objects.get(id=article_id), 'comments': Comments.objects.filter(comments_article_id=article_id)})

urls.py
from article import views
from django.conf.urls import url, include

urlpatterns = [
    url(r'^$', views.articles, name='articles'),
    url(r'^get/(?P<article_id>\d+)/$', views.article, name='article')



]

Here is the content of the settings.py project in the templates part
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',
            ],
        },
    },
]

Well, in short, I understand in theory what is wrong here, but how would I set it up correctly here, Django yells that
TemplateDoesNotExist at /articles/
main.html

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question