B
B
BotaniQ_Q2017-08-14 17:47:11
Django
BotaniQ_Q, 2017-08-14 17:47:11

Can't render template in Django?

The error is the following, here is the screen and below the text of the error09f33699ac8a4ad691be174697ce3c48.JPG

Error text
Page not found (404)
Request Method: GET
Request URL: 127.0.0.1:8000/articles/all
Using the URLconf defined in blog.urls, Django tried these URL patterns, in this order:
^admin/
^basicview/
^articles/ ^1/ [name='basic_one']
^articles/ ^2/ [name='basic_one2']
^articles/ ^articles/all/ [name='articles']
^articles/ ^articles/get/(?P\d+)/$ [name='article']
The current path, articles/all/, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

Complains that there seems to be no such url, but in the browser I try to open articles/all
Here is my views.py
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)})

Here is my urls.py in article app
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')



]

and here is my mean articles.html
<!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 question

Ask a Question

731 491 924 answers to any question