I would like to know how sort the posts displayed on the home page by data uploaded, I have dates saved to each post in the database. At the moment they are displayed in alphabetical order.
this is the route for the page I would like to display the images
HOME ROUTE:
#views.route("/")
def home():
title = Post.query.get("title")
date = Post.query.get("date")
images = os.listdir(os.path.join(staticpath, "uploads"))
return render_template('home.html', images=images, user=current_user, title=title, date=date, Post=Post, User=User)
HTML for page I want to display images by date
HTML PAGE:
{% extends "base.html" %}
{% block title %}home{% endblock %}
{% block content %}
<section class="list">
{% for image in images %}
<p> title: {{ Post.query.filter_by(name=image).first().title }}</p>
<p> date: {{ Post.query.filter_by(name=image).first().date}}</p>
<p> OP ID: {{ Post.query.filter_by(name=image).first().user_id}}
<section class="col-md-3 col-sm-6" >
<img src="{{ url_for('static', filename='uploads/' + image) }}"width = 530>
</section>
<a href="{{ url_for('static', filename='uploads/' + image) }}" style="absolute: 600;" download>{{ image }}</a>
<p class="solid" style="border-style: solid;"></p>
{% endfor %}
</section>
{% endblock %}
this is the database that posts are stored, it includes date
DATABASE MODEL:
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100))
date = db.Column(db.DateTime(timezone=True), default = func.now())
minetype = db.Column(db.Text, nullable=False)
name = db.Column(db.Text, nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
I would change the handler and the template as per below, which will allow you to achieve:
all Posts will be loaded in one query, and immediately sorted
you will not be making DB queries within the template, making cleaner separation of concerns
def home():
title = Post.query.get("title")
date = Post.query.get("date")
# images below are list of strings
images = os.listdir(os.path.join(staticpath, "uploads"))
# images below is a collection of `Post` instances (and it is sorted)
images = Post.query.filter(Post.name.in_(images)).order_by(Post.date)
return render_template('home.html', images=images, user=current_user, title=title, date=date, Post=Post, User=User)
and your template would change as below:
{% extends "base.html" %}
{% block title %}home{% endblock %}
{% block content %}
<section class="list">
{% for image in images %}
<p> title: {{ image.title }}</p>
<p> date: {{ image.date }}</p>
<p> OP ID: {{ image.user_id }}</p>
<section class="col-md-3 col-sm-6" >
<img src="{{ url_for('static', filename='uploads/' + image.name) }}" width = 530>
</section>
<a href="{{ url_for('static', filename='uploads/' + image.name) }}" style="absolute: 600;" download>{{ image }}</a>
<p class="solid" style="border-style: solid;"></p>
{% endfor %}
</section>
{% endblock %}
Related
So I got a QuerySet result from an aggregate function to display in a low-spec eBay clone of mine. But my problem is displaying certain fields in the Django template as I want, for example, I want to display the highest bidder's username and bid. When I call the whole object itself like so {{winner}}, then it displays. But when I try to access its fields like so {{winner.user_id.username}}, I get no output although the QuerySet does execute.
When I try to get a field like so (winner.user_id.username):
When I only call winner:
models.py
from django.contrib.auth.models import AbstractUser
from django.db import models
CATEGORIES = [
('Appliances', 'Appliances'),
('Tech', 'Tech'),
('Gaming', 'Gaming'),
('Fashion', 'Fashion'),
('Sports and Fitness','Sports and Fitness'),
('Other','Other'),
("Hygiene and Medicine","Hygiene and Medicine"),
("Stationery","Stationery"),
('Decor', 'Decor'),
('Furniture','Furniture'),
('Cars and Mechanical Things','Cars and Mechanical Things'),
("Tools","Tools")
]
# Create models here
class User(AbstractUser):
pass
class Auction_Listing(models.Model):
user_id = models.IntegerField(default=1)
list_title = models.CharField(max_length=64)
desc = models.TextField(max_length=600)
img_url = models.URLField(max_length=200, null=True, blank=True)
start_bid = models.IntegerField()
category = models.CharField(choices=CATEGORIES, max_length=35, null=True, blank=True)
active = models.BooleanField(default=True)
def __str__(self):
return f"ID:{self.id}, {self.list_title}: {self.desc}, {self.start_bid} posted by user:{self.user_id} in Category:{self.category}, url:{self.img_url}"
class Bids(models.Model):
user_id = models.ForeignKey('User', on_delete=models.CASCADE)
auctions = models.ForeignKey('Auction_Listing', on_delete=models.CASCADE, default=1,related_name='bidauc')
bid = models.IntegerField()
def __str__(self):
return f"ID:{self.id}, Bid {self.bid} posted by user:{self.user_id} on auction {self.auctions}"
class Auction_Comments(models.Model):
user_id = models.ForeignKey('User', on_delete=models.CASCADE)
comment = models.TextField(max_length=324, default='N/A')
auctions = models.ForeignKey('Auction_Listing', on_delete=models.CASCADE, default=1,related_name='comauc')
def __str__(self):
return f"ID:{self.id}, Comment: {self.comment} posted by user:{self.user_id} on auction {self.auctions}"
class Watchlist(models.Model):
user_id = models.ForeignKey('User', on_delete=models.CASCADE)
auctions = models.ForeignKey('Auction_Listing', on_delete=models.CASCADE, default=1, related_name='watchauc')
def __str__(self):
return f"ID:{self.id}, user:{self.user_id} on auction {self.auctions}"
views.py
def render_listing(request, title):
if request.method == "POST":
form = BidForm(request.POST)
bid = int(request.POST['new_bid'])
listing = Auction_Listing.objects.get(list_title=title)
comments = Auction_Comments.objects.filter(auctions=listing)
if bid <= listing.start_bid:
error = True
else:
error = False
listing.start_bid = bid
listing.save()
new_bid = Bids(user_id=request.user, auctions=listing, bid=bid)
new_bid.save()
return render(request, 'auctions/listing.html', {
"listing": listing,
"form": form,
"comments": comments,
"error": error,
"comform": CommentForm()
})
else:
form = BidForm()
comform = CommentForm()
listing = Auction_Listing.objects.get(list_title=title)
comments = Auction_Comments.objects.filter(auctions=listing)
high_bid = Bids.objects.filter(auctions=listing).aggregate(maximum=Max("bid"))
winner = Bids.objects.filter(auctions=listing, bid=high_bid['maximum'])
print(winner)
return render(request, 'auctions/listing.html', {
"listing": listing,
"form": form,
"comments": comments,
"error": False,
"comform": comform,
"winner": winner
})
template's code:
{% extends "auctions/layout.html" %}
{% load static %}
{% block title %} Listing: {{listing.list_title}} {% endblock %}
{% block body %}
{% if listing.active %}
<h2>{{ listing.list_title }}</h2>
<div class='listing'>
{% if listing.img_url == "" or listing.img_url == None %}
<a href='#'><img src="{% static 'auctions/img404.png' %}" class='img-fluid'></a>
{% else %}
<a href='#'><img src="{{ listing.img_url }}" class="img-fluid" alt='image of {{ listing.list_title }}'></a>
{% endif %}
<p>
{{ listing.desc }}
</p>
<p>
Current Bid: ${{ listing.start_bid }}
</p>
<p>Category: {{ listing.category }}</p>
<p></p>
{% if user.is_authenticated %}
<div class="bid">
<a href='{% url "watch" listing.list_title %}' class='btn btn-primary'>Add to/Remove from Watchlist</a>
{% if listing.user_id == user.id %}
<a href='{% url "close" listing.list_title %}' class='btn btn-primary'>Close Auction</a>
{% endif %}
</div>
<div class="bid">
<h3>Bid:</h3>
<form method="POST" action='{% url "renlist" listing.list_title %}'>
{% csrf_token %}
{{form}}
<button type="submit" class='btn btn-primary'>Make New Bid</button>
{% if error %}
Please enter a bid higher than the current bid.
{% endif %}
</form>
</div>
{% else %}
<p><a href='{% url "register" %}' class='register'>Register</a> to bid on this item and gain access to other features</p>
{% endif %}
</div>
<div class="listing">
<h3>Comments:</h3>
{% if user.is_authenticated %}
<div id='comform'>
<h4>Post a Comment</h4>
<form method="POST" action="{% url 'commentadd' %}">
{% csrf_token %}
{{comform}}
<button type="submit" class="btn btn-primary">Post Comment</a>
</form>
</div>
{% endif %}
<p>
{% for comment in comments %}
<div class="comment">
<h4>{{comment.user_id.username}} posted:</h4>
<p>{{comment.comment}}</p>
</div>
{% empty %}
<h4>No comments as of yet</h4>
{% endfor %}
</p>
</div>
{% else %}
<h2>This auction has been closed</h2>
<div>
<a href='{% url "watch" listing.list_title %}' class='btn btn-primary'>Add to/Remove from Watchlist</a>
</div>
<p>{{winner.user_id.username}}</p>
{% endif %}
{% endblock %}
Thanks in advance for the help!
Kind Regards
PrimeBeat
This will give a QuerySet. You can see in your second image.
A QuerySet represents a collection of objects from your database.
winner = Bids.objects.filter(auctions=listing, bid=high_bid['maximum'])
You need to iterate over that QuerySet, get whatever data you want and show it in your template.
{% for win in winner %}
<p>{{ win.user_id.username }}</p>
{% endfor %}
I'm trying to build a Wish list, I have a model for the listings, and a model for the wish list,
I have succeeded in making it work but..
I have to loop over all the listings first and match with the product id in my wish list so i can access the fields such as title and image..
is there any easier way to do this than looping over all the listings until finding the matched ones ?
views.py
def add_to_wishlist(request, product_id):
product = WishList.objects.filter(listing_id=product_id, user=request.user.username)
if product:
product.delete()
else:
product = WishList()
product.listing_id = product_id
product.user = request.user.username
product.save()
return HttpResponseRedirect(request.META['HTTP_REFERER'])
def wishlist(request):
product = WishList.objects.filter(user=request.user)
all_listings = AuctionListing.objects.all()
return render(request, "auctions/wishlist.html", {
'wishlist': product,
'all_listings': all_listings
})
models.py
class AuctionListing(models.Model):
title = models.CharField(max_length=100)
description = models.TextField()
start_bid = models.IntegerField(null=True)
image = models.CharField(max_length=1000, blank=True)
category = models.CharField(max_length=100)
seller = models.CharField(max_length=100, default="Default_Value")
class WishList(models.Model):
user = models.CharField(max_length=64)
listing_id = models.IntegerField()
wishlist.html
{% extends "auctions/layout.html" %}
{% block title %}Users Wishlist {% endblock %}
{% block body %}
<div class="col-12 mx-auto">
<h1 class="h3">My Wishlist</h1>
<div>Manage your wishlist</div>
{% if wishlist %}
{% for listing in all_listings %}
{% for product in wishlist %}
{% if listing.id == product.listing_id%}
<div class="card-mb-3">
<div class="row g-0">
<div class="col-md-4">
<img src="{{ listing.image }}" class="img-responsive" >
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">{{listing.title}}</h5>
<p class="card-text"> {{listing.description}}</p>
<p class="card-text"><small class="text-muted">{{listing.start_bid}}</small></p>
</div>
</div>
</div>
</div>
{% endif %}
{% endfor %}
{% endfor %}
{% else %}
<p class="card-text">No products have been added to your wishlist yet</p>
{% endif %}
</div>
{% endblock %}
Because you're getting all the WishList objects for the user, you don't need to just gather all AuctionListing objects and iterate over them. You can query them using the IDs on the WishLists you get back.
I'd do something like;
views.py
def wishlist(request):
wishlists = WishList.objects.filter(user=request.user)
listing_ids = wishlists.values_list('listing_id', flat=True)
listings = AuctionListing.objects.filter(pk__in=listing_ids)
return render(request, "auctions/wishlist.html", {
'wishlists': wishlists,
'listings': listings
})
wishlist.html
{% extends "auctions/layout.html" %}
{% block title %}Users Wishlist {% endblock %}
{% block body %}
<div class="col-12 mx-auto">
<h1 class="h3">My Wishlist</h1>
<div>Manage your wishlist</div>
{% if wishlists and listings %}
{% for listing in listings %}
<div class="card-mb-3">
<div class="row g-0">
<div class="col-md-4">
<img src="{{ listing.image }}" class="img-responsive" >
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">{{listing.title}}</h5>
<p class="card-text"> {{listing.description}}</p>
<p class="card-text"><small class="text-muted">{{listing.start_bid}}</small></p>
</div>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p class="card-text">No products have been added to your wishlist yet</p>
{% endif %}
</div>
{% endblock %}
I must get post if my category == academic (SelectField choice). But it doesn't work (posts are not shown). How can I get post data or form data for this?
I've tried
#categories.route("/category/academic")
def academic():
page = request.args.get('page', 1, type=int)
posts = Post.query.order_by(
Post.date_posted.desc()).filter(
Post.category == "Academic").paginate(page=page, per_page=5)
return render_template('academic.html', posts=posts)
and
#categories.route("/category/academic")
def academic():
form = PostForm()
page = request.args.get('page', 1, type=int)
post = Post(title=form.title.data,
content=form.content.data,
category=form.category.data)
posts = Post.query.order_by(
Post.date_posted.desc()).order_by(
post.category == "Academic").paginate(page=page, per_page=5)
return render_template('academic.html', posts=posts)
and
#categories.route("/category/academic")
def academic():
page = request.args.get('page', 1, type=int)
posts = Post.query.order_by(
Post.date_posted.desc()).filter(
**PostForm**.category == "Academic").paginate(page=page, per_page=5)
return render_template('academic.html', posts=posts)
Post.category
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
date_posted = db.Column(db.DateTime, nullable=False,
default=datetime.utcnow)
content = db.Column(db.Text, nullable=False)
category = db.Column(db.String(50))
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
PostForm.category
class PostForm(FlaskForm):
title = StringField('Title', validators=[DataRequired()])
content = TextAreaField('Content', validators=[DataRequired()])
category = SelectField('Category', validators=[DataRequired()], choices=[(
'Academic', 'Academic'), ('Art', 'Art')])
submit = SubmitField('Post')
Template (category.html)## This template for posts - Showing the category.html - All of template
{% extends "layout.html" %} {% block content %} {% for post in posts.items %}
<article class="media content-section">
<img
class="rounded-circle article-img"
src="{{ url_for('static', filename='profile_pics/' + post.author.image_file) }}"
/>
<div class="media-body">
<div class="article-metadata">
<a
class="mr-2"
href="{{ url_for('users.user_posts', username=post.author.username) }}"
>{{ post.author.username }}</a
>
<small class="text-muted">{{
post.date_posted.strftime("%Y-%m-%d")
}}</small>
<small class="article-category">
<mark
><a
class="mr-2"
href="{{ url_for('categories.category_route', category=post.category) }}"
>{{ post.category }}</a
></mark
>
</small>
</div>
<h2>
<a
class="article-title"
href="{{ url_for('posts.post', post_id=post.id) }}"
>{{ post.title }}</a
>
</h2>
<p class="article-content">{{ post.content }}</p>
</div>
</article>
{% endfor %} {% for page_num in posts.iter_pages(left_edge=1, right_edge=1,
left_current=1, right_current=2) %} {% if page_num %} {% if posts.page ==
page_num %}
<a class="btn btn-info mb-4" href="{{ url_for('main.home', page=page_num) }}">{{
page_num
}}</a>
{% else %}
<a
class="btn btn-outline-info mb-4"
href="{{ url_for('main.home', page=page_num) }}"
>{{ page_num }}</a
>
{% endif %} {% else %} ... {% endif %} {% endfor %} {% endblock content %}
Doesn't work because posts are not shown.
Well this works fine here. I copied your model, and parts of your template, which I further simplified for testing purposes. It works all just fine and results in your browser adapt nicely to the nr of items per page. In example below it is set on 2, but it works with 5 as well. Bear in mind you can only use attributes that are covered in the model and your query. Currently you have multiple issues on that. I suspect that your template is causing that you don't see any results.
python code:
page = request.args.get('page', 1, type = int)
posts = Post.query.filter_by(category = 'Academic').paginate(page=page, per_page=2)
Template:
{% extends "layout.html" %}
{% block content %}
{% for post in posts.items %}
<a href="" > {{ post.title }} </a>
{{ post.category }}
<p> {{ post.content }} </p>
{% endfor %}
{% for page_num in posts.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %}
{% if page_num %}
{% if posts.page == page_num %}
<a class="btn btn-info mb-4" href="{{ url_for('home.home', page = page_num) }}">{{ page_num }}</a>
{% else %}
<a class="btn btn-outline-info mb-4" href="{{ url_for('home.home', page = page_num) }}"> {{ page_num }} </a>
{% endif %}
{% endif %}
{% endfor %}
{% endblock content %}
There are 3 models in my web application. Event (self-made), User (imported from django.contrib.auth.models) and EventAttendance (self-made).
EventAttendance is a table which connects Event and User table (through foreign keys person_key and event_key).
I would like to create a button which will connect the user (the one who is logged in) and the Event. It should insert a line into the table EventAttendance.
I was trying to make it work but unfortunatelly it is not doing anything. Right now i am able to put data into EventAttendance table just through the ADMIN tab.
Could somebody please check my code and give me some advices?
MODELS
class Event(models.Model):
author = models.ForeignKey('auth.User')
title = models.CharField(max_length=200)
place = models.CharField(max_length=100)
start = models.DateTimeField()
price = models.IntegerField()
text = models.TextField()
created_date = models.DateTimeField(
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
class EventAttendance(models.Model):
person_key = models.ForeignKey(User, on_delete=models.CASCADE)
event_key = models.ForeignKey('Event', on_delete=models.CASCADE)
attended = models.BooleanField()
def __str__(self):
return "%s - %s" % (self.event_key, self.person_key)
FORMS`
class EventForm(forms.ModelForm):
class Meta:
model = Event
fields = ('title', 'text','place','start','price',)
class EventAttendanceForm(forms.ModelForm):
class Meta:
model = EventAttendance
widgets = {
'event_key': forms.HiddenInput(),
}
fields = ['person_key', 'event_key', 'attended',]
class UserCreateForm(UserCreationForm):
email = forms.EmailField(required=True)
class Meta:
model = User
fields = ( "username", "email" )
VIEW
def event_attendance(request,pk):
event = get_object_or_404(Event, pk=pk)
#if request.method == "POST":
form = EventAttendanceForm(request.POST)
EventAttendance = form.save(commit=False)
EventAttendance.person_key = user.id
EventAttendance.event_key = event.id
EventAttendance.attended = 1
EventAttendance.save()
return redirect('event_detail', pk=event.pk)
return render(request, 'events/post_detail.html', )
def event_new(request):
if request.method == "POST":
form = EventForm(request.POST)
if form.is_valid():
event = form.save(commit=False)
event.author = request.user
event.published_date = timezone.now()
event.save()
return redirect('event_detail', pk=event.pk)
else:
form = EventForm()
return render(request, 'events/post_edit.html', {'form': form})
TEMPLATE - where i use it
{% extends 'events/base.html' %}
{% block content %}
<div class="event">
{% if event.published_date %}
<div class="date">
<p> <u>Pridane:</u> {{ event.published_date }} </p>
<p> </p>
<p> <u>Autor:</u> {{ event.author }} </p>
<br>
</div>
{% endif %}
<a class="btn btn-default" href="{% url 'event_edit' pk=event.pk %}"><span class="glyphicon glyphicon-pencil"></span></a>
<a class="btn btn-default" href="{% url 'event_remove' pk=event.pk %}"><span class="glyphicon glyphicon-remove"></span></a>
<a class="btn btn-default" href="{% url 'event_attendance' pk=event.pk %}"><span class="glyphicon glyphicon-ok"></span></a>
<h1>{{ event.title }}</h1>
<p><u>Miesto</u>: {{ event.place }} </p>
<p><u>Zaciatok</u>: {{ event.start }} </p>
<p><u>Cena</u>: {{ event.price }} </p>
<br>
<p><u>Zucastneni:</u> {{attendance}}</p>
<br>
<p><u>Blizsie Informacie:</u></p>
<p>{{ event.text|linebreaksbr }}</p>
</div>
{% endblock %}
base.html
{% load staticfiles %}
<html>
<head>
<title>Eventovy katalog</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href="https://fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="{% static 'css/events.css' %}">
</head>
<body>
<div class="page-header">
{% if user.is_authenticated %}
<span class="glyphicon glyphicon-plus"></span>
{% endif %}
<h1>Eventovy katalog</h1>
</div>
<div class="content container">
<div class="row">
<div class="col-md-8">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</body>
post_edit.html
{% extends 'events/base.html' %}
{% block content %}
<h1>Pridaj event</h1>
<form method="POST" class="post-form">{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-default">Save</button>
</form>
{% endblock %}
If you need any additional details just pls let me know and ill upload them somewhere.
Thank you for your time!
This is my new function but i am still struggling with inserting new rows into my DB. Any suggestions?
def event_attendance(request):
event = get_object_or_404(Event)
attendance = EventAttendance(person_key = request.user ,
event_key = event.id, attended = True)
attendance.save(force_insert=True)
transaction.commit()
return render(request, 'events/post_detail.html')
The solution was in my urls.py file:
Previous value:
url(r'^post/(?P<pk>\d+)/$', views.event_attendance, name='event_attendance')
New value:
url(r'^post/(?P<pk>\d+)/attendance/$', views.event_attendance, name='event_attendance')
Maybe it is going to server someone in the future!
Wagtail Blog Site - Comment Model Form Issues
I'm creating a blog site, using Wagtail, and I've run in to a snag. I've added a Comment Model to my page, which I can add comments through the admin section and they display on the correct posts, but the comment form I've created is not displaying for some reason. Here's my relevant code. Any tips on where I went wrong would be greatly appreciated.
blog/models.py
class BlogPage(Page):
date = models.DateField("Post date")
intro = models.CharField(max_length=250)
body = RichTextField(blank=True)
#tag manager
tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
#get feature image
def main_image(self):
gallery_item = self.gallery_images.first()
if gallery_item:
return gallery_item.image
else:
return None
search_fields = Page.search_fields + [
index.SearchField('intro'),
index.SearchField('body'),
]
content_panels = Page.content_panels + [
MultiFieldPanel([
FieldPanel('date'),
FieldPanel('tags'),
], heading="Blog information"),
FieldPanel('intro'),
FieldPanel('body'),
InlinePanel('gallery_images', label="Gallery images"),
]
def serve(self, request):
# Get current page
post = self
# Get comment form
form = CommentForm(request.POST or None)
# Check for valid form
if form.is_valid():
comment = form.save(commit=False)
comment.post = post
comment.save()
return redirect(request.path)
return render_to_response(self,
{
'post': post,
'form': form,
},
context_instance=RequestContext(request))
class Comment(models.Model):
post = models.ForeignKey(BlogPage, related_name='comments')
author = models.CharField(max_length=250)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
approved_comment = models.BooleanField(default=False)
def approve(self):
self.approved_comment = True
self.save()
def __unicode__(self):
return self.text
def __str__(self):
return self.text
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ('author', 'text',)
blog_page.html
{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}template-blogpage{% endblock %}
{% block content %}
<div class="section">
<div class="container">
<h1 class="title">{{ page.title }}</h1>
<p class="meta subtitle">{{ page.date }}</p>
{% with page.main_image as main_image %}
{% if main_image %}{% image main_image fill-500x300 %}{% endif %}
{% endwith %}
<p>{{ main_image.caption }}</p>
<div class="hero-body subtitle">{{ page.intro }}</div>
<div class="content">
{{ page.body|richtext }}
{% if page.tags.all.count %}
<div class="tags">
<h3>Tags</h3>
{% for tag in page.tags.all %}
<span class="tag is-primary is-medium is-link"><a style="color: white" href="{% slugurl 'tags' %}?tag={{ tag }}">{{ tag }}</a></span>
{% endfor %}
</div>
{% endif %}
<p>Return to blog archive</p>
<hr>
<br>
<form action="" method="POST">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input class="control button is-primary" type='submit' name='submit' value='Add Comment'>
</form>
<br>
<hr>
<div class="section">
{% if page.comments.all.count %}
<h2 class='subtitle'>Comments</h2>
<div class="comments">
{% for comment in page.comments.all %}
{% if comment.approved_comment %}
<div class="comment">
<h5 class="date">{{ comment.created_date }}</h5>
<strong><h3 class="title is-3">{{ comment.author }}</h3></strong>
<h4 class="subtitle is-5">{{ comment.text|linebreaks }}</h4>
<br>
<hr>
</div>
{% endif %}
{% empty %}
<br>
<p>No comments yet...</p>
{% endfor %}
</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}
Now I'm getting an error saying:
File "/home/kenneth/development/web/sites/mysite/dynamicsalesops/blog/models.py", line 88, in serve
context_instance=RequestContext(request))
TypeError: render_to_response() got an unexpected keyword argument 'context_instance'
Your view_post function is never used. In Wagtail, rendering pages as HTML is handled by a serve method on the page model itself, not by a separate view function: http://docs.wagtail.io/en/v1.9/reference/pages/theory.html#anatomy-of-a-wagtail-request