we are currently building a cryptocurrency market (university project)
Each user has different cryptocurrencies in his "Wallet"
The wallet should show the sum (+ and - transactions) for each of the different cryptocurrencies.
For the moment we are only able to render a list which doesn't group the different currencies (those who have the same name)
We tried the sum and annotate functions. By doing so we aren't able to display the currency name. We get only the currency id
Here is our models file
class Currency(models.Model):
currency_name = models.CharField(max_length=40, unique=True)
symbol = models.ImageField(blank=True)
ticker = models.CharField(max_length=10)
created_at = models.DateTimeField(auto_now_add = True, null=True)
class Transaction(models.Model):
listing_id = models.ForeignKey(Listing, on_delete=models.CASCADE, null=True, blank=True)
created_at = models.DateTimeField(auto_now_add = True)
exchange_amount = models.IntegerField(null=True)
user_debit = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_id_debit', null=True)
user_credit = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_id_credit', null=True)
currency_id = models.ForeignKey(Currency, on_delete=models.CASCADE, null=True)
And our views.py
#profile page
#login_required
def profile(request):
wallet = Transaction.objects.filter(Q(user_credit=request.user) | Q(user_debit=request.user)).order_by('-created_at')
transactions = Transaction.objects.filter(Q(user_credit=request.user) | Q(user_debit=request.user)).order_by('-created_at')[:10]
listings = Listing.objects.filter(user=request.user).order_by('-created_at')[:10]
args = {'wallets': wallet, 'transactions': transactions, 'listings': listings}
return render(request, 'profile.html', args)
<!--This is our custom head title for the different urls. The base.html is loaded after this.-->
<head>
<title>SolvayCoin - Profile</title>
</head>
{% extends 'base.html' %}
{% block content %}
{% if user.is_authenticated %}
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<div class="container">
<h1 class="display-4">{{ user.first_name }} {{ user.last_name }}'s profile</h1>
<p>Username is <pan style="font-style: italic">{{ user.username }}</pan> and joined SolvayCoin {{ user.date_joined|timesince }} ago</p>
</div>
</div>
<div class="container extra-padding">
<hr>
<div class="row">
<div class="col-md-4">
<h2>My wallet</h2>
<ul class=list-unstyled >
{% for wallet in wallets %}
<li>{{ wallet.currency_id }}: {{ wallet.exchange_amount__sum|floatformat:"2" }}</li>
{% endfor %}
</ul>
</div>
<div class="col-md-4">
<h2>My transactions</h2>
{% if transactions %}
<ul class=list-unstyled >
{% for transactions in transactions %}
<li>
{% if user == transactions.user_credit %}
(+)
{% elif user == transactions.user_debit %}
(-)
{% endif %}
{{ transactions.currency_name_fixed }}{{ transactions.exchange_amount|floatformat:"2" }}
with {% if user == transactions.user_credit %}{{ transactions.user_debit }}{% elif user == transactions.user_debit %}{{ transactions.user_credit }}{% endif%}
</li>
{% endfor %}
</ul>
{% else %}
<p>No transactions are available.</p>
{% endif %}
</div>
<div class="col-md-4">
<h2>My listings</h2>
{% if listings %}
<ul class=list-unstyled >
{% for listings in listings %}
<li>Listing <!--{{ listings.id }}--> created {{ listings.created_at|date:'d/m/Y' }} at {{ listings.created_at|date:'H:i' }}</li>
{% endfor %}
</ul>
{% else %}
<p>No listings are available.</p>
{% endif %}
</div>
</div>
{% endif %}
<hr>
</div> <!-- /container -->
{% endblock %}
A django queryset solution seems tricky; since debit/credit resolution is also required here.
If performance and doing it in DB are not a major concern; I would do it in python as follows:
wallet_transactions = Transaction.objects.filter(Q(user_credit=request.user) | Q(user_debit=request.user)).order_by('-created_at').select_related('currency_id')
wallet = get_wallet(request.user, wallet_transactions)
def get_wallet(user, wallet_transactions):
wallet = defaultdict(int)
for txn in wallet_transactions:
if user == txn.user_credit:
wallet[txn.crrency_id.currency_name] += txn.exchange_amount
elif user == txn.user_debit:
wallet[txn.crrency_id.currency_name] -= txn.exchange_amount
else:
# Error; invalid transaction
pass
return wallet
# This will return something like this: {'SBS': 300, 'BTC': 121000}
I'd also think that there will be more business logic that gets added to get_wallet which definitely makes sense to be kept in the business layer of your application (python).
In your html; you can iterate over the wallet contents and print as follows:
<ul>
{% for currency_name, amount in wallet.items %}
<li>{{currency_name}} - {{amount}}</li>
{% endfor %}
</ul>
In your specific case; change this snippet:
<ul class=list-unstyled >
{% for currency_name, amount in wallet.items %}
<li>{{ currency_name }}: {{ amount|floatformat:"2" }}</li>
{% endfor %}
</ul>
Related
views.py :
def gerechten(request):
template = loader.get_template('café/gerechten.html')
mydata = gerecht_info.objects.all()
mydata2 = gerechten_Categorie.objects.all()
context = {
'mygerecht': mydata,
'mycategories': mydata2
}
return HttpResponse(template.render(context, request))
models.py :
class gerechten_Categorie(models.Model):
categorie = models.CharField(max_length=200)
def __str__(self):
return self.categorie
class gerecht_info(models.Model):
categorie = models.ForeignKey(gerechten_Categorie, on_delete=models.CASCADE)
gerecht_name = models.CharField(max_length=200)
gerecht_description = models.CharField(max_length=500, blank=True, null=True)
gerecht_price = models.CharField(max_length=50)
def __str__(self):
return self.gerecht_name
def drinkdesc(self):
return self.gerecht_description
def drinkprice(self):
return self.gerecht_price
gerechten.html :
{% if mygerecht %}
{% for cat in mygerecht %}
<div class="flex">
<div class="menu-head center">
<h2>{{cat.categorie}}</h2>
</div>
<div class="menu-item">
<ul class="price">
<li>{{cat.gerecht_name}}</li>
<li>€{{cat.gerecht_price}}</li>
</ul>
{% if cat.gerecht_description %}
<p>{{cat.gerecht_description}}</p>
{% else %}
<p></p>
{% endif %}
</div>
</div>
{% endfor %}
{% else %}
<div class="menu-head center">
<h2>no items avaible</h2>
</div>
{% endif %}
Looks like this but I want all info from 'Hapjes' into 1 'Hapjes' category, not separated.
I think what you are trying to achieve can be done with regroup template tag.
{% regroup mygerecht by categorie as article_categories %}
{% for categorie in article_categories %}
<div class="flex">
<div class="menu-head center">
<h2>{{categorie.grouper}}</h2>
</div>
{% for article in categorie.list %}
<div class="menu-item">
<ul class="price">
<li>{{article.gerecht_name}}</li>
<li>€{{article.gerecht_price}}</li>
</ul>
<p>{% if article.gerecht_description %}{{article.gerecht_description}}{% endif %}</p>
</div>
{% endfor %}
</div>
{% endfor %}
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 %}
Hey guys I get this error thrown up at me when I click a product on my Django project. I assume its a spelling mistake in either my view or models but I cant see anything. I've attach both an image of the error and my code. Any help would be appreciated. apologies if my post does not contain the correct information needed I'm new to coding.
Views
from django.shortcuts import render, get_object_or_404
from .models import Category,Product
def allProdCat(request, category_id=None):
c_page = None
products = None
if category_id != None:
c_page = get_object_or_404(Category, id=category_id)
products = Product.objects.filter(category=c_page, available=True)
else:
products = Product.objects.all().filter(available=True)
return render(request,'shop/category.html',{'category':c_page, 'products':products})
def prod_detail(request,category_id,product_id):
try:
product = Product.objects.get(category_id=category_id,id=product_id)
except Exception as e:
raise e
return render(request,'shop/product.html', {'product':product})
models
import uuid
from django.db import models
from django.urls import reverse
class Category(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False)
name = models.CharField(max_length=250, unique=True)
description = models.TextField(blank=True)
class Meta:
ordering = ('name',)
verbose_name = 'category'
verbose_name_plural = 'categories'
def get_absolute_url(self):
return reverse('phoneshop:products_by_category', args=[self.id])
def __str__(self):
return self.name
class Product(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False)
name = models.CharField(max_length=250, unique=True)
description = models.TextField(blank=True)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
price = models.DecimalField(max_digits=10, decimal_places=2)
image = models.ImageField(upload_to='product', blank=True)
stock = models.IntegerField()
available = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True, blank=True, null=True)
updated = models.DateTimeField(auto_now_add=True, blank=True, null=True)
class Meta:
ordering = ('name',)
verbose_name = 'product'
verbose_name_plural = 'products'
def get_absolute_url(self):
return reverse('phoneshop:prod_detail', args=[self.category.id, self.id])
def __str__(self):
return self.name
category.html:
{% extends "base.html" %}
{% load static %}
{% block metadescription %}
{% if category %}
{{ category.description|truncatewords:155 }}
{% else %}
Welcome to the cushion store where you can buy comfy and awesome cushions.
{% endif %}
{% endblock %}
{% block title %}
{% if category %}
{{ category.name }} - The Fantastic Electronic ShopnDrop
{% else %}
See our wide range of products including everything from phones to tablets - The Fantastic Electronic ShopnDrop
{% endif %}
{% endblock %}
{% block content %}
<!--Breadcrumb navigation-->
{% if category %}
<div class="row my_row_class">
<div class="mx-auto">
<p>Our Product Collection | {{category.name}}</p>
</div>
</div>
{% endif %}
<div class="mx-auto">
{% if category %}
<img class="my_image" src="{{category.image.url}}" alt="{{category.name}}">
</div>
<br>
<div>
<h1 class="text-center my_title">{{category.name}}</h1>
<p class="text-justify">{{category.description}}</p>
</div>
{% else %}
<img class="my_image my_image_padding" src="{% static 'images/banner.jpg' %}" alt="Our Products Collection">
</div>
<br>
<div>
<h1 class="text-center my_title">Our Products Collection</h1>
<p class="text-justify">Find a phone can be difficult at the best of times. With horrible products and prices its a nightmare
But with our wide range of products, The Fantastic Electronic ShopnDrop, could one be the one stop shop
for you.
</p>
</div>
{% endif %}
<div class="container">
<div class="row mx-auto">
{% for product in products %}
<div class="my bottom margin col-9 col-lg-4 col-sm-12 col-md-4">
<div class="cart text-center" style="min-width: 18rem;">
<img class = "card-img-top my_image"><img src="{{product.image.url}}" alt="{{product.name}}">
<div class="card-body">
<h4>{{product.name}}</h4>
<p>€{{product.price}}</p>
</div>
</div>
</div>
{% endfor %}
</div>
<br>
</div>
{% endblock %}
product.html
{% extends "base.html" %}
{% load static %}
{% block metadescription %}
{{ product.description|truncatewords:155 }}
{% endblock %}
{% block title %}
{{ product.name }} - The Fantastic Electronic ShopnDrop
{% endblock %}
{% block content %}
<div class="row my_prod_row_class">
<div class="mx-auto">
<p>Home | {{product.category}} | {{product.name}}</p>
</div>
<div class="container">
<br>
<div class="row">
<div class="col-12 col-sm-12 col-ml-12 col-lg-6 text-center">
<div style="min-width: 18rem;">
<img src="{{product.image.url}}" alt="{{product.name}}">
</div>
</div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div>
<div>
<h1 class="my_prod_title"></h1>{{product.name}}</h1>
<p>€{{product.price}}</p>
<p class="my_title">Product Description</p>
<p class="text-justify my_prod_text">{{product.description}}</p>
{% if product.stock == 0%}
<p class="text-justify my_prod_text"><b>Out of Stock</b></p>
{% else %}
Add to Cart
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
urls
from django.urls import path
from . import views
app_name ='phoneshop'
urlpatterns = [
path('', views.allProdCat, name ='allProdCat'),
path('<uuid:category_id>/', views.allProdCat, name='products_by_category'),
path('<uuid:cateogry_id>/<uuid:product_id>/', views.prod_detail, name='prod_detail'),
]
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