(Please help) The templates files (html) i added on my django blog app inst reflecting

23 views
Skip to first unread message

Chardonnay Saint Patrick

unread,
Jan 16, 2019, 10:01:19 AM1/16/19
to django...@googlegroups.com
Hi all,
 I am currently building a blog app using django 2, i have just created a templates folder in which i added the base.html files and all but it seems the views arent reflecting and i cant seem to figure out what im not doing right. 

 Based on the examples am following this is what the output should be:

image.png

How ever this what i still see:

django pic.PNG
These are my codes below:

views.py

from django.shortcuts import render, get_object_or_404
from .models import Post
from django.http import HttpResponse 

def base(request):

return render(request,'templates/blog/base.html')

def post_list(request):
posts = Post.published.all()
return render(request,
'templates/blog/post/list.html',
{'posts': posts})

def post_detail(request, year, month, day, post):
post = get_object_or_404(Post, slug=post,
status='published',
publish__year=year,
publish__month=month,
publish__day=day)
return render(request,
'templates/blog/post/detail.html',
{'post': post})

admin.py

from django.contrib import admin
from .models import Post

@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
list_display = ('title', 'slug', 'author', 'publish',
'status')
list_filter = ('status', 'created', 'publish', 'author')
search_fields = ('title', 'body')
prepopulated_fields = {'slug': ('title',)}
raw_id_fields = ('author',)
date_hierarchy = 'publish'
ordering = ('status', 'publish')

models.py

from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
from django.urls import reverse


class PublishedManager(models.Manager):
def get_queryset(self):
return super(PublishedManager,
self).get_queryset()\
.filter(status='published')

class Post(models.Model):
STATUS_CHOICES = (
('draft', 'Draft'),
('published', 'Published'),
)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250,
unique_for_date='publish')
author = models.ForeignKey(User,
on_delete=models.CASCADE,
related_name='blog_posts')
body = models.TextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10,
choices=STATUS_CHOICES,
default='draft')
def get_absolute_url(self):
return reverse('blog:post_detail',
args=[self.publish.year,
self.publish.month,
self.publish.day,
self.slug])
class Meta:
ordering = ('-publish',)

def __str__(self):
return self.title
# ...
objects = models.Manager() # The default manager.
published = PublishedManager() # Our custom manager


base.html


{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link href="{% static "css/blog.css" %}" rel="stylesheet">
</head>
<body>
<div id="content">
{% block content %}
{% endblock %}
</div>
<div id="sidebar">
<h2>My blog</h2>
<p>This is my blog.</p>
</div>
</body>
</html>

abel otugeme

unread,
Jan 16, 2019, 10:17:29 AM1/16/19
to django...@googlegroups.com

You have a base for all similar codes and the actual HTML for the page which contains code exclusive to that page alone. You need to create another HTML file for your home and then extend it from your base template using { % extends 'blog/base.html' %}

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAxRwFNcFcr3zpvNBPnKdjSJanSu6Cx5a__%2BrWC_yuO3zFdEwg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Chardonnay Saint Patrick

unread,
Jan 16, 2019, 12:39:14 PM1/16/19
to django...@googlegroups.com
I am new to django and i dont quite get what you mean by the above comment 

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages