Answer the question
In order to leave comments, you need to log in
Can't render template in Django?
The error is the following, here is the screen and below the text of the error
from django.shortcuts import render
from django.shortcuts import render_to_response
from django.http.response import HttpResponse
from article.models import Article, Comments
# Create your views here.
def basic_one(reguest):
view = "basic_one"
html = "<html><body>This is first view named %s view </body></html>" %view
return HttpResponse(html)
def basic_one2(reguest):
view = "basic_one2 text"
return render_to_response('myview.html', {'name': view})
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)})
from article import views
from django.conf.urls import url, include
urlpatterns = [
url(r'^1/', views.basic_one, name='basic_one'),
url(r'^2/', views.basic_one2, name='basic_one2'),
url(r'^articles/all/', views.articles, name='articles'),
url(r'^articles/get/(?P<article_id>\d+)/$', views.article, name='article')
]
<!Doctype html>
<html>
<head>
<title>Articles</title>
</head>
<body>
{% for article in articles %}
<h1>{{article.article_title}}</h1>
<h2>{{article.article_text}}</h2>
<h3>{{article.article_date}}</h3>
<h4>{{article.article_likes}}</h4>
{% endfor %}
</div>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question