Django: Joining a group Works, But I cant leave A group - django

I have added the join group functionality, and it works fine. Now, However, Im trying to add the leave group functionality, which seems like it would be similar, but it isn't working, and not throwing me an error either. here is the code for both join and leave group. it should be noted that there is a M2M relationship between User and Group.
(urls.py):
from . import views
from django.urls import path
app_name = 'groups'
urlpatterns = [
path('create/', views.create, name='create'),
path('index/', views.index, name='index'),
path('<int:group_id>/', views.detail, name='detail'),
path('<int:group_id>/join/', views.join, name='join'),
path('<int:group_id>/leave/', views.join, name='leave'),
]
(views.py):
def join(request, group_id):
group = get_object_or_404(Group, pk= group_id)
if request.method == 'POST':
group.members.add(request.user)
group.save()
return redirect('/groups/' + str(group_id) )
else:
return render(request, '/groups/detail.html', {'group': group})
def leave(request, group_id):
group = get_object_or_404(Group, pk= group_id)
if request.method == 'POST':
if request.user in group.members.all:
group.members.remove(request.user)
group.save()
return redirect('home')
else:
return render(request, '/groups/index.html')
groups/detail.html
{% extends "base.html" %}
{% block content %}
<div class="row">
<div class="col-4">
<h1>{{group.name}}</h1>
</div>
<div class="col-6">
<p>{{group.description}}</p>
</div>
{% if user in group.members.all %}
<div class="col-2">
<button class="btn btn-primary btn-lg btn-block"> Leave {{product.members.count}}</button>
</div>
{% else %}
<div class="col-2">
<button class="btn btn-primary btn-lg btn-block"> Join {{product.members.count}}</button>
</div>
{% endif %}
</div>
<div class="row">
<div class="col-4">
<img src="{{group.image.url}}" alt="">
</div>
</div>
<br>
<br>
<div class="row bootstrap snippets">
<div class="col-md-3 container-widget">
<div class="panel panel-info panel-widget">
<div class="panel-title text-center">
Group Members
</div>
<div class="panel-body">
{% for member in group.members.all %}
<ul class="basic-list image-list">
<li><b>{{member.username}}</li>
</ul>
{% endfor %}
</div>
</div>
</div>
</div>
<form method ='POST' id= 'leave' action="{% url 'groups:leave' group.id %}" >
{% csrf_token %}
<input type="hidden" >
</form>
<form method ='POST' id= 'join' action="{% url 'groups:join' group.id %}" >
{% csrf_token %}
<input type="hidden" >
</form>
{% endblock %}
enter code here

group.members.all is a method, you need to call it.
But don't do this; it unnecessarily queries all the members from the database. You could possibly use exists(), but actually there is no reason to check at all; remove() is a no-op if the item is not present. Just call it.
Also, you don't need to all .save() after modifying a many-to-many relationship.

You have views.join written twice, the second should be views.leave

The only problem with your leave function view is that you omitted the parenthesis to the if statement eg. if request.user in group.members.all(): so i figured that when you add the parenthesis it should work.
def leave(request, user_id):
if request.method == 'POST':
group = get_object_or_404(Group, pk=group_id)
if request.user in group.members.all():
group.members.remove(request.user)
group.save()
return redirect('home')
return HttpResponse("You have been removed successfully " + str(user.username))
else:
return render(request, '/groups/index.html')
I think it might be better to rename your group model in other to avoid naming conflict with the django Group model. as your model inherit from the Django model, I will suppose you do something like this:
class GroupExtend(models.Model):
...then your other fields etc.

Related

Django- Template not found

I can't seem to get my delete, edit and add review functionality working. The errors come as soon as I try to navigate to the urls I have set up. When I try and add a new review using my link on the reviews page I get the below message:
TemplateDoesNotExist at /reviews/add
I don't understand why because I have linked the url above to the template, which I have created.
The issue I have with my edit/delete views is that the url it searches for when I click the button is just /edit/ or /delete/ rather than reviews/edit/int:pk or reviews/delete/int:pk as per my urls.
I have pasted my code below, any help would be much appreciated! I have the feeling I am going to kick myself when I realise!
reviews.html:
{% extends "base.html" %}
{% load static %}
{% block content %}
<div class="container-fluid home-container">
<div class="row align-items-center">
<div class="col-sm-12 text-center mt-4">
<h2><strong>Reviews</strong></h2>
</div>
</div>
{% for review in reviews %}
<hr class="hr-1">
<div class="row featurette">
<div class="col-sm-12">
<h2 class="featurette-heading">{{ review.title }}</h2>
<p class="lead">{{ review.content }}</p>
<div class="row justify-content-between mx-1">
<p>By: {{ review.user }}</p>
<p>Created on: {{ review.created }}</p>
<p>Last Updated: {{ review.updated }}</p>
</div>
<!-- Add user authentication if -->
<div class="text-center">
<a href="edit/{{ review.id }}" class="mx-2">
<button class="positive-button mb-2">Edit</button></a>
<a href="delete/{{ review.id }}" class="mx-2 mb-2">
<button class="negative-button">Delete</button></a>
</div>
</div>
</div>
{% endfor %}
<div class="row">
<div class="col-sm-12 text-center py-4">
{% if user.is_authenticated %}
<a href="{% url 'home:add_review' %}">
<button class="positive-button-lg">Add a review</button>
</a>
{% else %}
<p>If you would like to add your own review, please login or sign up if you haven't already!</p>
{% endif %}
</div>
</div>
</div>
{% endblock %}
add_review.html:
{% extends "base.html" %}
{% load static %}
{% block content %}
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-auto text-center p-3">
<form method="post" style="margin-top: 1.3em;">
{{ review_form }}
{% csrf_token %}
<button type="submit" class="btn btn-primary btn-lg">Submit</button>
</form>
</div>
</div>
{% endblock %}
views.py:
from django.shortcuts import render
from django.views import View
from django.urls import reverse_lazy
from django.views.generic import UpdateView, DeleteView
from .models import Reviews
from .forms import ReviewForm
def home(request):
''' Returns the home page.'''
return render(request, 'home/index.html')
def reviews(request):
''' Returns the reviews page.'''
serialized_reviews = []
reviews = Reviews.objects.all()
for review in reviews:
serialized_reviews.append({
"title": review.title,
"content": review.content,
"user": review.user,
"created": review.created,
"updated": review.updated,
})
context = {
"reviews": serialized_reviews
}
print(serialized_reviews)
return render(request, 'home/reviews.html', context)
class AddReview(View):
'''View which allows the user to add a new review.'''
def get(self, request, *args, **kwargs):
review = Reviews
review_form = ReviewForm
context = {
'review': review,
'review_form': review_form,
'user': review.user,
'title': review.title,
'content': review.content,
}
return render(request, 'add_review.html', context)
def post(self, request, *args, **kwargs):
review_form = ReviewForm(data=request.POST)
if review_form.is_valid():
obj = review_form.save(commit=False)
obj.user = request.user
obj.save()
return redirect("home:reviews")
class DeleteReview(DeleteView):
'''View which allows the user to delete the selected review.'''
model = Reviews
template_name = 'delete_review.html'
success_url = reverse_lazy('reviews')
class EditReview(UpdateView):
'''View which allows the user to edit the selected review.'''
model = Reviews
template_name = 'edit_review.html'
fields = ['title', 'content']
urls.py:
from django.urls import path
from . import views
app_name = 'home'
urlpatterns = [
path('', views.home, name='home'),
path('reviews', views.reviews, name='reviews'),
path('reviews/add', views.AddReview.as_view(), name='add_review'),
path('reviews/delete/<int:pk>', views.DeleteReview.as_view(), name='delete_review'),
path('reviews/edit/<int:pk>', views.EditReview.as_view(), name='edit_review'),
]
The main difference is my app name, which is 'core'. Also, I forgot to add the content field to the model, but that is easily done, the form will just handle it as soon as you do the migration. (except on list.html)
models.py
from django.db import models
from django.contrib.auth import get_user_model
from django.utils import timezone
class Reviews(models.Model):
user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
title = models.CharField(max_length=128)
created_at = models.DateTimeField(auto_now_add=timezone.now())
updated_at = models.DateTimeField(auto_now=timezone.now())
forms.py
from django import forms
from core.models import Reviews
class ReviewsForm(forms.ModelForm):
class Meta:
model = Reviews
fields = '__all__'
views.py
from core.models import Reviews
from core.forms import ReviewsForm
from django.shortcuts import render, redirect
def list_reviews(request):
reviews = Reviews.objects.all()
context = {
"reviews": reviews
}
return render(request, 'reviews/list.html', context)
def add_review(request):
if request.method == 'POST':
form = ReviewsForm(request.POST)
if form.is_valid():
form.save()
return redirect('/reviews/')
else:
form = ReviewsForm()
context = {
'form': form
}
return render(request, 'reviews/detail.html', context)
def edit_review(request, pk):
if request.method == 'POST':
form = ReviewsForm(request.POST)
if form.is_valid():
obj = Reviews.objects.get(id=pk)
obj.title = form.cleaned_data['title']
obj.user = form.cleaned_data['user']
obj.save()
return redirect('/reviews/')
else:
obj = Reviews.objects.get(id=pk)
form = ReviewsForm(instance=obj)
context = {
'form': form
}
return render(request, 'reviews/detail.html', context)
def delete_review(request, pk):
obj = Reviews.objects.get(id=pk)
obj.delete()
return redirect('/reviews/')
urls.py
from django.urls import path
import core.views as views
app_name = 'core'
urlpatterns = [
path('reviews/', views.list_reviews, name='list-reviews'),
path('reviews/add', views.add_review, name='add-review'),
path('reviews/edit/<int:pk>/', views.edit_review, name='edit-review'),
path('reviews/delete/<int:pk>/', views.delete_review, name='delete-review'),
]
list.html
{% extends "base.html" %}
{% load static %}
{% block content %}
<div class="container-fluid home-container">
<div class="row align-items-center">
<div class="col-sm-12 text-center mt-4">
<h2><strong>Reviews</strong></h2>
</div>
</div>
{% for review in reviews %}
<hr class="hr-1">
<div class="row featurette">
<div class="col-sm-12">
<h2 class="featurette-heading">{{ review.title }}</h2>
<p class="lead">{{ review.content }}</p>
<div class="row justify-content-between mx-1">
<p>By: {{ review.user }}</p>
<p>Created on: {{ review.created_at }}</p>
<p>Last Updated: {{ review.updated_at }}</p>
</div>
<!-- Add user authentication if -->
<div class="text-center">
<a href="{% url 'core:edit-review' pk=review.id %}" class="mx-2">
<button class="positive-button mb-2">Edit</button></a>
<a href="{% url 'core:delete-review' pk=review.id %}" class="mx-2 mb-2">
<button class="negative-button">Delete</button></a>
</div>
</div>
</div>
{% endfor %}
<div class="row">
<div class="col-sm-12 text-center py-4">
{% if user.is_authenticated %}
<a href="{% url 'core:add-review' %}">
<button class="positive-button-lg">Add a review</button>
</a>
{% else %}
<p>If you would like to add your own review, please login or sign up if you haven't already!</p>
{% endif %}
</div>
</div>
</div>
{% endblock %}
detail.html
{% extends "base.html" %}
{% load static %}
{% block content %}
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-auto text-center p-3">
<form method="post" style="margin-top: 1.3em;">
{% csrf_token %}
<table>
{{ form }}
</table>
<button type="submit" class="btn btn-primary btn-lg">Save</button>
</form>
</div>
</div>
{% endblock %}
According to your urls, It is a review/edit/<int:pk>.
So you must add same thing in href tag.
Change this:
<a href="edit/{{ review.id }}"
To this:
<a href="review/edit/{{ review.id }}"
That's why you are getting that error
I've fixed it, firstly the path in my add_review view was wrong, which I have amended and it now works (thanks Ivan).
I also was not actually bringing the ID through on my 'reviews' view in the first place, so when following the links on my edit and review buttons, it didn't know what I meant by 'id', as I hadn't specified what that was in the view context.
Thanks for the help all!
I think you're writing in your urls the wrong way, like this below your div text-center:
<a href="edit/{{ review.id }}" class="mx-2">
It should be:
<a href="{% url 'yourappname:edit' review.id %}">

Reverse for 'create_order' with no arguments not found. 1 pattern(s) tried: ['create_order/(?P<pk>[^/]+)/$']

I'm getting this error when I use
path('create_order/<str:pk>/', views.createOrder, name="create_order"),
but there is no such error when path is..
path('create_order', views.createOrder, name="create_order"),
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name="home"),
path('products/', views.products, name='products'),
path('customer/<str:pk_test>/', views.customer, name="customer"),
path('create_order/<str:pk>/', views.createOrder, name="create_order"),
path('update_order/<str:pk>/', views.updateOrder, name="update_order"),
path('delete_order/<str:pk>/', views.deleteOrder, name="delete_order"),
]
views.py
def createOrder(request, pk):
OrderFormSet = inlineformset_factory(Customer, Order , fields=('product','status'), extra=9)
customer = Customer.objects.get(id=pk)
formset = OrderFormSet(queryset=Order.objects.none(), instance=customer)
#form = OrderForm(initial={'customer':customer})
if request.method == 'POST':
#print('printing post', request.POST)
formset = OrderFormSet(request.POST, instance=customer)
if formset.is_valid():
formset.save()
return redirect('/')
context = {'formset': formset}
#return redirect('accounts/order_form.html', context)
return render(request, 'accounts/order_form.html', context)
i also have tried redirect, that's not working the problem is with urls.py.
customer.html
{% extends 'accounts/main.html' %}
{% block content %}
<br>
<div class="row">
<div class="col-md">
<div class="card card-body">
<h5>Customer:</h5>
<hr>
<a class="btn btn-outline-info btn-sm btn-block" href="">Update Customer</a>
<a class="btn btn-outline-info btn-sm btn-block" href="{% url 'create_order' customer.id %}">Place Order</a>
</div>
</div>
<div class="col-md">
<div class="card card-body">
<h5>Contact Information</h5>
<hr>
<p>Email: {{customer.email}}</p>
<p>Phone: {{customer.phone}}</p>
</div>
</div>
<div class="col-md">
<div class="card card-body">
<h5>Total Order</h5>
<hr>
<h1 style="text-align: center;padding: 10px;">{{order_count}}</h1>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col">
<div class="card card-body">
<form method="POST">
<button class="btn btn-primary" type="submit">Search</button>
</form>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md">
<div class="card card-body">
<table class="table table-sm">
<tr>
<th>Product</th>
<th>Category</th>
<th>Date Ordered</th>
<th>Status</th>
<th>Update</th>
<th>Remove</th>
</tr>
{% for order in orders %}
<tr>
<td>{{order.product}}</td>
<td>{{order.product.category}}</td>
<td>{{order.date_created}}</td>
<td>{{order.status}}</td>
<td><a class="btn btn-outline-info btn-md " href="{% url 'update_order' order.id %}">Update</a></td>
<td><a class="btn btn-outline-danger btn-md " href="{% url 'delete_order' order.id %}">Delete</a></td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endblock %}
models.py
class Customer(models.Model):
name = models.CharField(max_length=200, null=True, blank=True)
phone = models.CharField(max_length=200, null=True, blank=True)
email = models.CharField(max_length=200, null=True, blank=True)
date_created = models.DateTimeField(auto_now_add=True, null=True)
def __str__(self):
return self.name
order_form.html
{% extends 'accounts/main.html' %}
{% load static %}
{% block content %}
<div class="row">
<div class="col-md-6">
<div class="card card-body">
<form action="" method="POST">
{% csrf_token %}
{{formset.managment_form}} <!-- to remove the managmentForm data missing or has been tempered wiith , error -->
{% for form in formset %}
{{formset}} <!--in context of views.py -->
<hr>
{% endfor %}
<input class="btn btn-outline-success btn-md" type="submit" name="submit">
</form>
</div>
</div>
</div>
{% endblock %}
I have added the templates , and thanks to all but I think the only problem is with urls.py , because if I use
path('create_order/<str:pk>/', views.createOrder, name="create_order"),
instead of
path('create_order', views.createOrder, name="create_order"),
then I get error, otherwise there is no such error for the above path.
I finally got the error.
So, error was here
the href which we have used id {% url 'create_order' customer.id %}
and this is in customer.html ,so the customer.id will get value provided by the views.customer
but if you see in your view.customer,
context = {'customers':customers,'orders': orders,'orders_count': orders_count}
because we followed a tutorial video, that guy did some changes which we didn't because it isn't shown in the video.
the changes he did was that
he changed 'customers' to 'customer' and now context of customer.html is good
because now it knows what the hell is customer.id
i know where the problem is
in the dashboard.html you should delete the line includes {% url 'create_order' %}
I don't know what is the problem but just replaced the file urls.py from GitHub with the same context and it's not showing that error.
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name="home"),
path('products/', views.products, name='products'),
path('customer/<str:pk_test>/', views.customer, name="customer"),
path('create_order/<str:pk>/', views.createOrder, name="create_order"),
path('update_order/<str:pk>/', views.updateOrder, name="update_order"),
path('delete_order/<str:pk>/', views.deleteOrder, name="delete_order"),
]
views.py
from django.forms import inlineformset_factory
def createOrder(request, pk):
OrderFormSet = inlineformset_factory(Customer, Order, fields=('product', 'status'), extra=10 )
customer = Customer.objects.get(id=pk)
formset = OrderFormSet(queryset=Order.objects.none(),instance=customer)
#form = OrderForm(initial={'customer':customer})
if request.method == 'POST':
#print('Printing POST:', request.POST)
#form = OrderForm(request.POST)
formset = OrderFormSet(request.POST, instance=customer)
if formset.is_valid():
formset.save()
return redirect('/')
context = {'form':formset}
return render(request, 'accounts/order_form.html', context)
order_form.html
{% extends 'accounts/main.html' %}
{% load static %}
{% block content %}
<div class="row">
<div class="col-md-6">
<div class="card card-body">
<form action="" method="POST">
{% csrf_token %}
{{ form.management_form }}
{% for field in form %}
{{field}}
<hr>
{% endfor %}
<input type="submit" name="Submit">
</form>
</div>
</div>
</div>
{% endblock %}
Again I don't know why it was showing this error and where was the problem but just relapced it with the same code from GitHub and it worked.if someone know how it worked, that will be really helpful in near future.
in dashboard you should remove the line with create order
cause there is use of create_order url without id so there's an error

Redirect with get_context_data in generic detailview django

I have this view where i needed two models Book and UserFav so I used context for that:
class BookDetailView(LoginRequiredMixin, generic.DetailView):
model = Book
template_name = 'book_detail.html'
def get_context_data(self, **kwargs):
context = super(BookDetailView, self).get_context_data(**kwargs)
context.update({
'fav_list': UserFav.objects.filter(user=self.request.user)
})
return context
and another view function
def favorite(request, pk):
book = get_object_or_404(Book, pk=pk)
fav, created = UserFav.objects.get_or_create(user=request.user)
fav.favorites.add(book)
return render(request, 'book_detail.html', {'book': book})
form for the favourite function
<form action="{% url 'favorite' book.id %}" method="post" style="display: inline;">
{% csrf_token %}
<button type="submit" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-remove"></span> add this book to favourite
</button>
my url
url(r'^book/(?P<pk>\d+)$', views.BookDetailView.as_view(), name='book-detail'),
url(r'^book/(?P<pk>\d+)/f/$', views.favorite, name='favorite'),
where I need fav_list
{% if fav_list %}
{% for fav in fav_list %}
{% if book in fav.favorites.all %}Favorited
{% else %}
<form action="{% url 'favorite' book.id %}" method="post" style="display:inline;">
{% csrf_token %}
<button type="submit" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-remove"></span> add this book to favourite
</button>
</form>
{% endif %}
{% endfor %}
{% else %}
<form action="{% url 'favorite' book.id %}" method="post" style="display: inline;">
{% csrf_token %}
<button type="submit" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-remove"></span> add this book to favourite
</button>
</form>
{% endif %}
now the problem is that when i get redirected to book_detail.html I am not getting the fav_list which is needed for the template
How do I redirect properly or use some other way to define views?
You're not redirecting from the favorite view. Upon form submission, considered a good practice to redirect.
Try
from django.shortcuts import redirect
from django.urls import reverse
def favorite(request, pk):
book = get_object_or_404(Book, pk=pk)
fav, created = UserFav.objects.get_or_create(user=request.user)
fav.favorites.add(book)
# if you have an app_name in urls.py file try this
# return redirect(reverse('YOUR_APP_NAME:book-detail', args=(pk,)))
return redirect(reverse('book-detail', args=(pk,)))
I hope this will help.

how to handle same form on different pages (DRY)

I have a template called base.html. it contains a fixed search form at top of it. all of my other templates inherit from base.html. I want to my form works on every pages (right now I have 10 different pages).
One silly solution is to handle form for every single view, but it is opposite of DRY.
So how can I handle my form one time for all of views ?
NOTE: base.html is just a template and is not used directly by a view.
You need to create a separate app for 'search' and need to create views and templates accordingly.
I have an app called 'Products' in my Django project and it has the model called 'Product' and I use search to search from that model.
search/views.py:
from django.shortcuts import render
from django.views.generic import ListView
from products.models import Product
class SearchProductView(ListView):
template_name = "search/view.html"
def get_context_data(self, *args, **kwargs):
context = super(SearchProductView, self).get_context_data(*args, **kwargs)
query = self.request.GET.get('q')
context['query'] = query
# SearchQuery.objects.create(query=query)
return context
def get_queryset(self, *args, **kwargs):
request = self.request
method_dict = request.GET
query = method_dict.get('q', None) # method_dict['q']
if query is not None:
return Product.objects.search(query)
return Product.objects.featured()
'''
__icontains = field contains this
__iexact = fields is exactly this
'''
search/templates/view.html (to render the search results):
{% extends "base.html" %}
{% block content %}
<div class='row mb-3'>
{% if query %}
<div class='col-12' >
Results for <b>{{ query }}</b>
<hr/>
</div>
{% else %}
<div class='col-12 col-md-6 mx-auto py-5'>
{% include 'search/snippets/search-form.html' %}
</div>
<div class='col-12'>
<hr>
</div>
{% endif %}
</div>
<div class='row'>
{% for obj in object_list %}
<div class='col'>
{% include 'products/snippets/card.html' with instance=obj %}
{% if forloop.counter|divisibleby:3 %}
</div> </div><div class='row'><div class='col-12'><hr/></div>
{% elif forloop.counter|divisibleby:2 %}
</div> </div><div class='row'><div class='col-12'><hr/></div>
{% else %}
</div>
{% endif %}
{% endfor %}
</div>
{% endblock %}
search/templates/snippets/search-form.html:
<form method='GET' action='{% url "search:query" %}' class="form my-2 my-lg-0 search-form">
<div class='input-group'>
<input class="form-control" type="text" placeholder="Search" name='q' aria-label="Search" value='{{ request.GET.q }}'>
<span class='input-group-btn'>
<button class="btn btn-outline-success" type="submit">Search</button>
</span>
</div>
</form>
and, finally, urls.py for search app:
from django.conf.urls import url
from .views import (
SearchProductView
)
urlpatterns = [
url(r'^$', SearchProductView.as_view(), name='query'),
]
and include this in your main urls.py:
url(r'^search/', include("search.urls", namespace='search')),
I hope this helps.
Good luck!

Django search bar problems

I'm trying to implement a search bar to my website, it's not working and I can't seem to figure out why. The search form looks like this:
<form class="navbar-form navbar-left" role="search" method="GET" action="{% url 'search' %}">
<div class="form-group">
<input type="text" class="form-control" name="q" value="{{request.GET.q}}">
</div>
<button type="submit" class="btn">Search</button>
</form>
url.py:
url(r'^search/$', views.SearchView, name='search'),
views.py:
def SearchView(request):
products = Photos.objects.all()
query = request.GET.get("q")
if query:
products = products.filter( Q(category__contains=query) ).distinct()
return render(request, 'urcle/search.html', {'products': products})
else:
return render(request, 'urcle/search.html', {'products': products})
search.html:
{% extends 'urcle/base.html'%}
{%block content%}
{% if products %}
<div id="inner" >
{% for item in products %}
<div id = 'content' align="center" ></div>
<div class="col-sm-4 col-lg-2" style="width:30%" >
<div class="thumbnail" align="left" >
<a href="{{item.name}}">
<img src="http://ec2-54-194-123-114.eu-west-1.compute.amazonaws.com/images/{{ item.name }}.jpg" class="img-responsive">
</a>
<div class="caption" >
{{item.title}} </li>
<br/>
</div>
</div>
</div>
{% cycle '' '' '' '' '' '<div class="clearfix visible-lg"> </div>' %}
{% endfor %}
</div>
{% else %}
<h1>nothing to see here!!!</h1>
{% endif %}
{%endblock%}
What's really bugging me is that all that gets displayed is the part that gets extended from base.html not even the tag on the else statement gets displayed, anyone know whats up?
The problem was a conflicting URL, which was taking me to the wrong view function