Adding a range price filter - django

I'm trying to add a range price filter for a list of products with django and I'm having some trouble with how to proceed
Here's the code for the template : ( produits.html )
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
var user = '{{request.user}}'
function getToken(name)
{
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
var csrftoken = getToken('csrftoken');
</script>
</head>
<body>
{% block content %}
<div class="bg-light py-3">
<div class="container">
<div class="row">
<div class="col-md-12 mb-0">Home <span class="mx-2 mb-0">/</span> <strong class="text-black">Shop</strong></div>
</div>
</div>
</div>
<div class="site-section">
<div class="container">
<div class="row mb-5">
<div class="col-md-9 order-2">
<ul class="nav nav-pills flex-column mb-md-3">
<li class="nav-item">
<div class="nav-link active">Les Produits :</div>
</li>
</ul>
<div class="row mb-5">
{% for item in prod %}
<div class="col-sm-6 col-lg-4 mb-4" data-aos="fade-up">
<div class="block-4 text-center border">
<figure class="block-4-image">
<img src="{{item.imageURL}}" alt="Image placeholder" class="img-fluid">
</figure>
<div class="block-4-text p-4">
<p class="text-primary font-weight-bold">{{item.nom}}</p>
<p class="mb-0">{{item.description}}</p>
<p class="text-primary font-weight-bold">{{item.prix}}</p>
<button data-product="{{item.id}}" data-action="add" class="btn btn-outline-secondary add-btn update-cart"> Add to Cart</button>
View
</div>
</div>
</div>
{% endfor %}
</div>
<div class="row" data-aos="fade-up">
<div class="col-md-12 text-center">
<div class="site-block-27">
</div>
</div>
</div>
</div>
<div class="col-md-3 order-1 mb-5 mb-md-0">
<div class="border p-4 rounded mb-4">
<h3 class="mb-3 h6 text-uppercase text-black d-block">Categories</h3>
<ul class="list-unstyled mb-0">
{% for i in categ %}
<li class="mb-1"><span>{{i.nom}}</span> <span class="text-black ml-auto">{{nb}}</span></li>
{% endfor %}
</ul>
</div>
<div class="border p-4 rounded mb-4">
<div class="mb-4">
<h3 class="mb-3 h6 text-uppercase text-black d-block">Filter by Price</h3>
<div id="slider-range" class="border-primary"></div>
<input type="text" name="PRICE" id="amount" class="form-control border-0 pl-0 bg-white" disabled="" />
</div>
<div class="mb-4">
<h3 class="mb-3 h6 text-uppercase text-black d-block">Size</h3>
<label for="s_sm" class="d-flex">
<input type="checkbox" id="s_sm" class="mr-2 mt-1"> <span class="text-black">Small (2,319)</span>
</label>
<label for="s_md" class="d-flex">
<input type="checkbox" id="s_md" class="mr-2 mt-1"> <span class="text-black">Medium (1,282)</span>
</label>
<label for="s_lg" class="d-flex">
<input type="checkbox" id="s_lg" class="mr-2 mt-1"> <span class="text-black">Large (1,392)</span>
</label>
</div>
<div class="mb-4">
<h3 class="mb-3 h6 text-uppercase text-black d-block">Color</h3>
<a href="#" class="d-flex color-item align-items-center" >
<span class="bg-danger color d-inline-block rounded-circle mr-2"></span> <span class="text-black">Red (2,429)</span>
</a>
<a href="#" class="d-flex color-item align-items-center" >
<span class="bg-success color d-inline-block rounded-circle mr-2"></span> <span class="text-black">Green (2,298)</span>
</a>
<a href="#" class="d-flex color-item align-items-center" >
<span class="bg-info color d-inline-block rounded-circle mr-2"></span> <span class="text-black">Blue (1,075)</span>
</a>
<a href="#" class="d-flex color-item align-items-center" >
<span class="bg-primary color d-inline-block rounded-circle mr-2"></span> <span class="text-black">Purple (1,075)</span>
</a>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="site-section site-blocks-2">
<div class="row justify-content-center text-center mb-5">
<div class="col-md-7 site-section-heading pt-4">
<h2>Categories</h2>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-md-6 col-lg-4 mb-4 mb-lg-0" data-aos="fade" data-aos-delay="">
<a class="block-2-item" href="#">
<figure class="image">
<img src="{%static 'images/women.jpg' %}" alt="" class="img-fluid">
</figure>
<div class="text">
<span class="text-uppercase">Collections</span>
<h3>Women</h3>
</div>
</a>
</div>
<div class="col-sm-6 col-md-6 col-lg-4 mb-5 mb-lg-0" data-aos="fade" data-aos-delay="100">
<a class="block-2-item" href="#">
<figure class="image">
<img src="{%static 'images/children.jpg' %}" alt="" class="img-fluid">
</figure>
<div class="text">
<span class="text-uppercase">Collections</span>
<h3>Children</h3>
</div>
</a>
</div>
<div class="col-sm-6 col-md-6 col-lg-4 mb-5 mb-lg-0" data-aos="fade" data-aos-delay="200">
<a class="block-2-item" href="#">
<figure class="image">
<img src="{%static 'images/men.jpg' %}" alt="" class="img-fluid">
</figure>
<div class="text">
<span class="text-uppercase">Collections</span>
<h3>Men</h3>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="{%static 'js/cart.js' %}"></script>
{% endblock content %}
</body>
</html>
Here's the model code for products :
class Product(models.Model):
nom = models.CharField(max_length=200,null= True, blank=True)
prix = models.DecimalField(max_digits=7,decimal_places=2,null=True,blank=True)
description = models.TextField(null=True,blank=True)
nbr_stock = models.IntegerField(null=True,blank=True,default=0)
image= models.ImageField(null=True,blank=True)
taille= models.CharField(max_length=5,null=True,blank=True)
categorie=models.CharField(max_length=200,null= True, blank=True)
#property
def imageURL(self):
try :
url = self.image.url
except :
url = ''
return url
def __str__(self):
return self.nom
My question is how can I "retrieve" the value from the range slider and then show the products according to the price? thank you in advance

Related

Django - I want to display current rate depending on the category i select

here is my front-end and everything is working fine however, i don't want all rate to display at once, i want the rate to display one at a time depending on the card category i select.
From the image i uploaded, current rate of other card category are showing which i don't want, please i need help even if it will require using javascript of ajax
Here is my index(template)
{% for giftcard in giftcards %}
<!-- Card -->
<div class="col-lg-4 gift__card col-6 p-0">
<a type="button" class="btn">
<img class="img-fluid gift__card-img" src="{{ giftcard.card_image.url }}">
</a>
<div class="container d-flex align-items-center justify-content-center">
<div class="gift__card-modal-container py-5">
<div class="card__container">
<div class="gift__card-overlay"></div>
<div class="container-fluid bg-light gift__card-modal shadow-lg">
<div class="pop p-5">
<div class="row d-flex align-items-center justify-content-between">
<div class="col-lg-5 col-12 p-0 m-0">
<img class="img-fluid gift__card-img" style="width: 40rem;" src="{{ giftcard.card_image.url }}">
<p class="text-muted">Select the card category and the amount.</p>
</div>
<div class="col-lg-6 col-sm-12 card-details">
<form class="card-form">
<div class="form-group py-2">
<label for="card-category">Card category</label>
<select id="category" class="form-select py-2" aria-label="Default select example">
{% for spec in giftcard.category_set.all %}
<option value="{{ spec.category }}">{{ spec.category }}</option>
{% endfor %}
</select>
</div>
<div class="form-group py-2">
<label for="Amount">Amount</label>
<div class="d-flex align-items-center amount">
<input type="text" class="form-control" id="amount"
placeholder="Please enter amount">
<span class="">#100,000</span>
</div>
</div>
<div class="form-group py-3">
{% for spec in giftcard.category_set.all %}
<label for="rate">Current rate - {{ spec.rate }}</label>
{% endfor %}
</div>
<div class="border-none pt-2 pl-3 d-flex justify-content-end">
<button type="button" class="btn process-card-btn">Proceed</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="gift__terms-card hide fade" id="terms" tabindex="-1" role="dialog"
aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content terms">
<div class="p-5">
<h4 class="terms-title pb-4">Trading terms</h4>
{% for spec in giftcard.category_set.all %}
<p class="pb-2">{{ spec.terms }}</p>
{% endfor %}
<div class="border-none pt-3 pl-3 d-flex justify-content-end">
<button type="button" class="btn process-card-btn">Proceed</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
Here is my models
class Giftcard(models.Model):
name = models.CharField(max_length=100, unique=True)
card_image = models.ImageField(upload_to='Giftcard/', blank=False)
date = models.DateTimeField(auto_now_add=True)
publish = models.BooleanField(default=False)
class Category(models.Model):
category = models.CharField(max_length=250)
rate = models.IntegerField()
terms = models.TextField()
card_category = models.ForeignKey(Giftcard, on_delete=models.CASCADE)
Here is my views
def giftcard(request):
giftcards = Giftcard.objects.filter(publish=True)
context = {
'giftcards': giftcards
}
return render(request, 'dashboard/giftcard.html', context)

URL automatically changes & it gives me the error of Page not found

"127.0.0.1:8000/adminpanel/edit_gallary/29"
So this is the main problem when I first edit it works properly. But when I want to edit the second time URL automatically changes & it changes this way.
"127.0.0.1:8000/adminpanel/edit_gallary/edit_gallary/29"
This is my views.py file:
def edit_gallary(request,gallaryid):
table = gallary.objects.get(id=gallaryid)
gallary_form = gallaryform(instance=table)
if request.method=='POST':
form = gallaryform(data=request.POST, files=request.FILES, instance=table)
if form.is_valid():
form.save()
table=gallary.objects.all()
return render(request,"gallary1.html",{'table':table})
context = {'gallary_form':gallary_form}
return render(request,'edit_gallary.html',context)
This is my URLS.py file:
path('edit_gallary/<int:gallaryid>',views.edit_gallary,name="edit gallery"),
This is my edit_gallary.html file:
{% extends 'index.html' %}
{% block content %}
<body>
<div class="main-wrapper">
<div class="app" id="app">
<header class="header">
<div class="header-block header-block-collapse d-lg-none d-xl-none">
<button class="collapse-btn" id="sidebar-collapse-btn">
<i class="fa fa-bars"></i>
</button>
</div>
<div class="header-block header-block-nav">
<ul class="nav-profile">
<li class="profile dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button"
aria-haspopup="true" aria-expanded="false">
<div class="img"
style="background-image: url('https://avatars3.githubusercontent.com/u/3959008?v=3&s=40')">
</div>
<span class="name">Admin</span>
</a>
<div class="dropdown-menu profile-dropdown-menu" aria-labelledby="dropdownMenu1">
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">
<i class="fa fa-power-off icon"></i> Logout </a>
</div>
</li>
</ul>
</div>
</header>
<aside class="sidebar">
<div class="sidebar-container">
<div class="sidebar-header">
<div class="brand">
<div class="logo">
<span class="l l1"></span>
<span class="l l2"></span>
<span class="l l3"></span>
<span class="l l4"></span>
<span class="l l5"></span>
</div> Compare school
</div>
</div>
<nav class="menu">
<ul class="sidebar-menu metismenu" id="sidebar-menu">
<li>
<a href="insert_school">
<i class="fa fa-home"></i>Back</a>
</li>
</ul>
</nav>
</div>
</aside>
<div class="sidebar-overlay" id="sidebar-overlay"></div>
<div class="sidebar-mobile-menu-handle" id="sidebar-mobile-menu-handle"></div>
<div class="mobile-menu-handle"></div>
<article class="content responsive-tables-page">
<div class="title-block">
<h1 class="title">Gallary</h1>
<p class="title-description"></p>
</div>
<section class="section">
<div class="row">
<div class="table-responsive">
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<table class="table table-striped table-bordered">
{{ gallary_form }}
<tr>
<td class="text-right mb-3">
<input type="submit" value="register" class="btn btn-primary" >
</td>
</tr>
</table>
</form>
</div>
</div>
</section>
</article>
</div>
</div>
<script src="js/vendor.js"></script>
<script src="js/app.js"></script>
{% endblock %}
</body>
It seems you need to change 'edit_gallary/<int:gallaryid>' to '<int:gallaryid>/edit_gallary/' in urls.py or just try adding a slash to the route end in your path

Undefined Path In Django

I am working on a django application and everything is working fine except I am getting an error Not Found: /about-us/undefined when I visit the url 127.0.0.1:8000/about-us/
With a view as below the error is not showing:
def about_us(request):
if request.method == 'GET':
return HttpResponse('<h1>About Page</h1>')
But when I render an HTML template as shown below then the error shows
def home(request):
if request.method == 'GET':
return render(request, 'website_files/index.html', {'home' : True})
website.urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name="home"),
path('about-us/', views.about_us, name="about-us"),
path('why_us/', views.why_us, name="why_us"),
path('out_team/', views.out_team, name="out_team"),
path('it_solutions/', views.it_solutions, name="it_solutions"),
path('it_solutions/it_management_services', views.it_management_services, name="it_management_services"),
path('it_solutions/cyber_security_services', views.cyber_security_services, name="cyber_security_services"),
path('it_solutions/software_dev_services', views.software_dev_services, name="software_dev_services"),
path('it_solutions/networking_and_cloud_services', views.networking_services, name="networking_and_cloud_services"),
path('it_solutions/it_consultations', views.consulting_services, name="it_consultations"),
path('it_solutions/data_backup_and_recovery', views.backup_services, name="data_backup_and_recovery"),
path('it_solutions/email_hosting', views.email_hosting, name="email_hosting"),
path('it_solutions/web_hosting', views.web_hosting, name="web_hosting"),
path('stories', views.blogging, name="stories"),
path('contact_us', views.contact, name="contact_us"),
path('find_out', views.find_out, name="find_out"),
path('request_quote', views.get_quote, name="request_quote"),
]
main urls.py
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# path('admin/', admin.site.urls),
path('', include('website.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
What am I missing? You assistance will greatly appriciated.
Edit
Below is the index.html
index.html
{% extends 'website_files/base.html' %}
{% load static %}
{% block content %}
<section class="slider">
<div class="slick-carousel carousel-arrows-light carousel-dots-light m-slides-0"
data-slick='{"slidesToShow": 1, "arrows": true, "dots": true, "speed": 700,"fade": true,"cssEase": "linear"}'>
<div class="slide-item align-v-h bg-overlay">
<div class="bg-img"><img src="{% static 'assets/images/sliders/Top-6-Software-Development-Methodologies.jpg' %}" alt="slide img"></div>
<div class="container">
<div class="row align-items-center">
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-7">
<div class="slide-item__content">
<h2 class="slide-item__title">Latest Software To Your Possible Customers!!</h2>
<p class="slide-item__desc">We are experienced professionals who understand that IT services are
changing, and are true partners who care about your success.</p>
Get Started
</div>
</div>
</div>
</div>
</div>
<div class="slide-item align-v-h bg-overlay">
<div class="bg-img"><img src="{% static 'assets/images/sliders/Online-Presence.jpg' %}" alt="slide img"></div>
<div class="container">
<div class="row align-items-center">
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-7">
<div class="slide-item__content">
<h2 class="slide-item__title">Online Presence <br> To Ensure High Availability.</h2>
<p class="slide-item__desc">We understand the importance of having an online presence. We are therefore, strive to help you have a digital footprint</p>
Get Started
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="features-layout3 pt-0 pb-90 bg-gray">
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-8">
<div class="row features-wrapper">
<div class="col-sm-4 feature-item">
<h4 class="feature-item__title">Software Asset</h4>
<p class="feature-item__desc">All aspects of your software assets including development, purchasing, deployment &
maintenance.</p>
<i class="icon-arrow-right icon-outlined"></i>
</div>
<div class="col-sm-4 feature-item">
<h4 class="feature-item__title">Enterprise Services</h4>
<p class="feature-item__desc">Ranging from but not limited to IT Counsultation, Software Development, Email Hosting etc.</p>
<i class="icon-arrow-right icon-outlined"></i>
</div>
<div class="col-sm-4 feature-item">
<h4 class="feature-item__title">Custom Requests</h4>
<p class="feature-item__desc">We build bespoke and dynamic systems with associated workflows, and tasks.</p>
<i class="icon-arrow-right icon-outlined"></i>
</div>
</div>
</div>
<div class="col-sm-12 col-md-12 col-lg-4">
<div class="feature-item feature-item-custom bg-primary">
<h4 class="feature-item__title">Thinking insights, verified and realtime information help you
make the right decisions!
</h4>
<a href="{% url 'it_solutions' %}" class="btn btn__white btn__link">
<span>Find Your Solution</span><i class="icon-arrow-right icon-outlined"></i>
</a>
</div>
</div>
</div>
</div>
</section>
<section class="about-layout6 bg-gray pt-0 pb-0">
<div class="container">
<div class="row heading-layout2 mb-70">
<div class="col-12">
<h2 class="heading__subtitle color-body">Nationwide Service, Local Expertise</h2>
</div>
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-7">
<h3 class="heading__title mb-30">Keep your business safe & ensure high availability.</h3>
</div>
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-5 about__Text">
<h5 class=" mb-30">Message from our Founder.</h5>
<p>Here at <b>TechTitan</b>, we strive to help you improve efficiency, leverage tech, and provide better customer experiences with the modern technology
services available all over the world. Our skilled personnel, utilising the latest technologies
combined with decades of experience will help you and your business archieve the standard that you strive for and give you a competitive advantage over your peers</p>
<!-- <img src="{% static 'assets/images/about/Isaac.jpg' %}" alt="singnture" class="mb-20"> -->
</div>
</div>
</div>
<div class="image-wrapper bg-white">
<div class="container">
<div class="row align-items-end">
<div class="col-sm-12 col-md-12 col-lg-7">
<div class="about__img">
<img src="{% static 'assets/images/about/IMG_0752.jpg' %}" alt="about">
</div>
</div>
<!-- <div class="col-sm-12 col-md-12 col-lg-5">
<ul class="list-items list-unstyled mb-30" style="margin-top: -500px;">
<li> Continued support to our clients</li>
<li> Provided the best solutions that your need</li>
<li> Ensuring that you are moving with the changing worldmwith our updates</li>
</ul>
<a href="{% url 'about-us' %}" class="btn btn__primary btn__icon btn__xl">
<span>More About Us</span><i class="icon-arrow-right"></i>
</a>
</div> -->
</div>
</div>
</div>
</section>
<section class="services-layout2 services-masonry bg-no-repeat bg-size-auto bg-top-right pt-130 pb-90">
<div class="bg-img"><img src="{% static 'assets/images/backgrounds/6.png' %}" alt="background"></div>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-6 offset-lg-3">
<div class="heading heading-layout2 text-center mb-50">
<h2 class="heading__subtitle">Only settle for the best</h2>
<h3 class="heading__title">Our technology allows you to offer the best service to your possible
customers!
</h3>
</div>
</div>
</div>
<div class="row services-wrapper">
<div class="col-sm-12 col-md-6 col-lg-4">
<div class="service-item">
<div class="service-item__content">
<div class="service-item__icon">
<i class="icon-server"></i>
</div>
<h4 class="service-item__title">IT Management <br> Services</h4>
<p class="service-item__desc">IT management services that manages and oversees the IT infrastructure of your
organization responsible for networking and operations.</p>
<a href="{% url 'it_management_services' %}" class="btn btn__secondary btn__link">
<span>Read More</span>
<i class="icon-arrow-right"></i>
</a>
</div>
<div class="service-item__overlay bg-overlay bg-overlay-primary">
<div class="bg-img"><img src="{% static 'assets/images/services/1.jpg' %}" alt="background"></div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6 col-lg-4">
<div class="service-item">
<div class="service-item__content">
<div class="service-item__icon">
<i class="icon-cloud"></i>
</div>
<h4 class="service-item__title">Cyber Security<br> Services</h4>
<p class="service-item__desc">Drive your business and manage risk with us when it comes
cyber security, cloud, and manage security services and extend your team with leading experts.</p>
<a href="{% url 'cyber_security_services' %}" class="btn btn__secondary btn__link">
<span>Read More</span>
<i class="icon-arrow-right"></i>
</a>
</div>
<div class="service-item__overlay bg-overlay bg-overlay-primary">
<div class="bg-img"><img src="{% static 'assets/images/services/2.jpg' %}" alt="background"></div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6 col-lg-4">
<div class="service-item">
<div class="service-item__content">
<div class="service-item__icon">
<i class="icon-programming"></i>
</div>
<h4 class="service-item__title">Software Development<br> Services</h4>
<p class="service-item__desc">We develop solutions that help you make informed decisions that keep your business going forward especially with rapid changes we face on a daily basis.</p>
<a href="{% url 'software_dev_services' %}" class="btn btn__secondary btn__link">
<span>Read More</span>
<i class="icon-arrow-right"></i>
</a>
</div>
<div class="service-item__overlay bg-overlay bg-overlay-primary">
<div class="bg-img"><img src="{% static 'assets/images/services/5.jpg' %}" alt="background"></div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6 col-lg-4">
<div class="service-item">
<div class="service-item__content">
<div class="service-item__icon">
<i class="icon-network"></i>
</div>
<h4 class="service-item__title">Networking and Cloud Computing<br> Services</h4>
<p class="service-item__desc">Cloud computing is the on-demand, availability of computer system
resources, especially data storage and computing power, without direct active management by the user.
</p>
<a href="{% url 'networking_and_cloud_services' %}" class="btn btn__secondary btn__link">
<span>Read More</span>
<i class="icon-arrow-right"></i>
</a>
</div>
<div class="service-item__overlay bg-overlay bg-overlay-primary">
<div class="bg-img"><img src="{% static 'assets/images/services/3.jpg' %}" alt="background"></div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6 col-lg-4">
<div class="service-item">
<div class="service-item__content">
<div class="service-item__icon">
<i class="icon-technician"></i>
</div>
<h4 class="service-item__title">IT Consulting <br> Services</h4>
<p class="service-item__desc">Trying to implement new technologies can be a challenge. With us on you side, we will give you information on the current technologies to ensure you have the best technologies possible.</p>
<a href="{% url 'it_consultations' %}" class="btn btn__secondary btn__link">
<span>Read More</span>
<i class="icon-arrow-right"></i>
</a>
</div>
<div class="service-item__overlay bg-overlay bg-overlay-primary">
<div class="bg-img"><img src="{% static 'assets/images/services/4.jpg' %}" alt="background"></div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6 col-lg-4">
<div class="service-item">
<div class="service-item__content">
<div class="service-item__icon">
<i class="icon-file"></i>
</div>
<h4 class="service-item__title">Backup & Recovery<br> Services</h4>
<p class="service-item__desc">While you can’t predict unexpected events, we’ll ensure the right
precautions are in place to minimize downtime and keep you moving in the right direction.</p>
<a href="{% url 'data_backup_and_recovery' %}" class="btn btn__secondary btn__link">
<span>Read More</span>
<i class="icon-arrow-right"></i>
</a>
</div>
<div class="service-item__overlay bg-overlay bg-overlay-primary">
<div class="bg-img"><img src="{% static 'assets/images/services/6.jpg' %}" alt="background"></div>
</div>
</div>
</div>
</div>
<div class="row align-items-center">
<div class="col-sm-12 col-md-12 col-lg-5">
<p class="fz-16 my-4">Trusted by multiple organizations, for 5 years and running, it has been
delivering
smiles to hundreds of IT advisors, developers, users, and business owners.
</p>
</div>
<div class="col-sm-12 col-md-12 col-lg-7 d-flex align-items-center justify-content-end">
Find Your Solution
</div>
</div>
</div>
</section>
<section id="features" class="features-layout1 pt-130 pb-220">
<div class="bg-img"><img src="{% static 'assets/images/backgrounds/10.jpg' %}" alt="background"></div>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
<div class="heading heading-layout2 mb-40">
<h2 class="heading__subtitle color-body">Ensure High Availability of Your Services</h2>
<h3 class="heading__title color-white">Easy solutions for all difficult IT problems, keep businesses safe &
ensure high availability.</h3>
</div>
<a href="{% url 'contact_us' %}" class="btn btn__white btn__bordered btn__xl btn__icon minwidth-170">
<span>Get Started</span>
<i class="icon-arrow-right"></i>
</a>
</div>
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
<div class="row features-wrapper mt-40">
<div class="col-sm-6 feature-item">
<div class="feature-item__icon">
<i class="icon-statistic"></i>
</div>
<div class="d-flex align-items-center justify-content-between">
<h4 class="feature-item__title mb-0">Software Development</h4>
<i class="icon-arrow-right icon-outlined"></i>
</div>
</div>
<div class="col-sm-6 feature-item">
<div class="feature-item__icon">
<i class="icon-management"></i>
</div>
<div class="d-flex align-items-center justify-content-between">
<h4 class="feature-item__title mb-0">IT Counsultation</h4>
<i class="icon-arrow-right icon-outlined"></i>
</div>
</div>
<div class="col-sm-6 feature-item">
<div class="feature-item__icon">
<i class="icon-software"></i>
</div>
<div class="d-flex align-items-center justify-content-between">
<h4 class="feature-item__title mb-0">Email Hosting</h4>
<i class="icon-arrow-right icon-outlined"></i>
</div>
</div>
<div class="col-sm-6 feature-item">
<div class="feature-item__icon">
<i class="icon-relational"></i>
</div>
<div class="d-flex align-items-center justify-content-between">
<h4 class="feature-item__title mb-0">Website Hosting</h4>
<i class="icon-arrow-right icon-outlined"></i>
</div>
</div>
</div>
<div class="row mt-50 contact-text">
<div class="col-sm-9 px-0">
<strong class="color-white">If you have any questions or need help, feel free to contact with our team,
or call
(+260) 966477311</strong>
</div>
<div class="col-sm-3 px-0 d-flex justify-content-end">
Contact Us
</div>
</div>
</div>
</div>
</div>
</section>
<div class="bg-no-repeat bg-top">
<div class="bg-img"><img src="{% static 'assets/images/backgrounds/11.jpg' %}" alt="backgrounds"></div>
<section id="contact" class="contact-layout2 pt-0">
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="contact-panel d-flex flex-wrap mt--170">
<div class="contact-panel__banner bg-overlay bg-overlay-primary d-flex flex-column justify-content-between" style="background-color:red">
<div class="bg-img"><img src="{% static 'assets/images/banners/6.jpg' %}" alt="background"></div>
<div class="heading heading-layout2 heading-light">
<h3 class="heading__title mb-30">Perfect Solutions For Your Business!</h3>
<p class="heading__desc mb-30">TechTitan has been helping organizations throughout the World to manage
their IT with our unique approach to technology management and consultancy solutions. </p>
</div>
<div class="d-flex flex-wrap">
<a href="{% url 'contact_us' %}" class="btn btn__white btn__bordered btn__icon">
<span>Get Started</span><i class="icon-arrow-right"></i>
</a>
</div>
</div>
<form class="contact-panel__form" method="post" action="{% url 'find_out' %}" id="contactForm">
<div class="row">
<div class="col-sm-6 col-md-6 col-lg-6">
<div class="form-group">
<label for="contact-name">Name (required)</label>
<input type="text" required class="form-control" placeholder="Name" id="contact-name" name="contact-name"
required>
</div>
</div>
<div class="col-sm-6 col-md-6 col-lg-6">
<div class="form-group">
<label for="contact-email">Email (required)</label>
<input type="email" required class="form-control" placeholder="Email" id="contact-email"
name="contact-email" required>
</div>
</div>
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="form-group">
<label for="contact-Phone">Inquiry (required)</label>
<select required class="form-control">
<option value="">Select Service</option>
<option value="Email Hosting">IT Management</option>
<option value="IT Counsultation">Cyber Security</option>
<option value="Software Development">Software Development</option>
<option value="Website Developemnt">Networking And Cloud Computing</option>
<option value="Website Developemnt">IT Consulting</option>
<option value="Website Developemnt">Backup & Recovery</option>
<option value="Website Developemnt">Email Hosting</option>
<option value="Website Developemnt">Website Hosting</option>
</select>
</div>
</div>
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="form-group">
<label for="contact-message">Additional Details (required)</label>
<textarea required class="form-control" placeholder="Describe your inquiry!" id="contact-message"
name="contact-message"></textarea>
</div>
<button type="submit" class="btn btn__secondary btn__xl btn__block">Submit Request </button>
<div class="contact-result"></div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
</div>
<section class="clients border-top pt-50 pb-50">
<div class="container">
<div class="row align-items-center">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="slick-carousel"
data-slick='{"slidesToShow": 6, "arrows": false, "dots": false, "autoplay": true,"autoplaySpeed": 2000, "infinite": true, "responsive": [ {"breakpoint": 992, "settings": {"slidesToShow": 4}}, {"breakpoint": 767, "settings": {"slidesToShow": 3}}, {"breakpoint": 480, "settings": {"slidesToShow": 2}}]}'>
<div class="client">
<img src="{% static 'assets/images/clients/1.jpg' %}" alt="client">
<img src="{% static 'assets/images/clients/1.jpg' %}" alt="client">
</div>
<div class="client">
<img src="{% static 'assets/images/clients/Techmasters.png' %}" alt="client">
<img src="{% static 'assets/images/clients/Techmasters.png' %}" alt="client">
</div>
<div class="client">
<img src="{% static 'assets/images/clients/idsp.jpg' %}" alt="client">
<img src="{% static 'assets/images/clients/idsp.jpg' %}" alt="client">
</div>
<div class="client">
<img src="{% static 'assets/images/clients/4.png' %}" alt="client">
<img src="{% static 'assets/images/clients/4.png' %}" alt="client">
</div>
<div class="client">
<img src="{% static 'assets/images/clients/5.png' %}" alt="client">
<img src="{% static 'assets/images/clients/5.png' %}" alt="client">
</div>
<div class="client">
<img src="{% static 'assets/images/clients/6.png' %}" alt="client">
<img src="{% static 'assets/images/clients/6.png' %}" alt="client">
</div>
<div class="client">
<img src="{% static 'assets/images/clients/7.png' %}" alt="client">
<img src="{% static 'assets/images/clients/7.png' %}" alt="client">
</div>
</div>
</div>
</div>
</div>
</section>
<section class="banner-layout2 pt-0 pb-100">
<div class="bg-img"><img src="{% static 'assets/images/backgrounds/brickred.svg' %}" alt="background"></div>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-5">
<div class="banner-text">
<div class="heading-layout2 heading-light mb-40">
<h3 class="heading__title mb-30">Timely service delivery!!</h3>
<p class="heading__desc">We ensure that the services we offer are delivered when they are scheduled for. No delays because we understand that your business as to go forward at all times.
</p>
</div>
Get Started
</div>
</div>
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-7">
<div class="banner-img">
<img src="{% static 'assets/images/logo/TechTitan_Logo_1.jpg' %}" alt="banner">
</div>
</div>
</div>
</div>
</section>
{% endblock %}

Django data saved in the database but not show in the template

Django data is saved in the database but, when access the data in template its display nothing.the models.py, views.py and home.html file code is below, when I entered data in the field and print it in add function it display but does not display in the template. Im using the modal to display the data
models.py
from django.db import models
class ToDo(models.Model):
title = models.CharField(max_length=100)
detail = models.TextField()
published_date = models.DateTimeField()
def __str__(self):
return self.title
views.py
from django.shortcuts import render, HttpResponse, redirect
from django.utils import timezone
from todoapp.models import ToDo
def home(request):
todo_items = ToDo.objects.all()
context = {'todoItems': todo_items}
return render(request, 'todoapp/home.html', context)
def add(request):
if request.method=="POST":
addTitle = request.POST['addTitle']
addDetail = request.POST['addDetail']
current_date = timezone.now()
addedObject = ToDo.objects.create(title=addTitle, detail=addDetail, published_date=current_date)
return redirect('home')
return render(request, 'todoapp/home.html')
home.html "Template file"
{%load static%} {%include 'header.html'%}
<!-- Navigation -->
<nav class="navbar navbar-expand-lg bg-secondary text-uppercase fixed-top" id="mainNav">
<div class="container">
<a class="navbar-brand js-scroll-trigger" href="{% url 'home'%}">todo application</a>
<button class="navbar-toggler navbar-toggler-right text-uppercase font-weight-bold bg-primary text-white rounded" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
Menu
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item mx-0 mx-lg-1">
<a class="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger" data-toggle="modal" data-target="#addModal" href="add">add new</a>
</li>
<li class="nav-item mx-0 mx-lg-1">
<a class="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger" href="{%url 'home'%}">todo list</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Masthead -->
<header class="masthead bg-primary text-white text-center">
<div class="container d-flex align-items-center flex-column">
<!-- Masthead Avatar Image -->
<img class="masthead-avatar mb-5" src="{%static 'images/avataaars.svg' %}" alt="">
<!-- Masthead Heading -->
<h1 class="masthead-heading text-uppercase mb-0">Todo Application </h1>
<!-- Icon Divider -->
<div class="divider-custom divider-light">
<div class="divider-custom-line"></div>
<div class="divider-custom-icon">
<i class="fas fa-star"></i>
</div>
<div class="divider-custom-line"></div>
</div>
<!-- Masthead Subheading -->
<p class="masthead-subheading font-weight-light mb-0">Web Developer - Web Designer - Coder</p>
</div>
</header>
<!-- Portfolio Section -->
<section class="page-section portfolio" id="portfolio">
<div class="container">
<!-- Portfolio Section Heading -->
<h2 class="page-section-heading text-center text-uppercase text-secondary mb-0">portfolio</h2>
<!-- Icon Divider -->
<div class="divider-custom">
<div class="divider-custom-line"></div>
<div class="divider-custom-icon">
<i class="fas fa-star"></i>
</div>
<div class="divider-custom-line"></div>
</div>
<!-- Portfolio Grid Items -->
<div class="row">
<!-- Portfolio Item 1 -->
<div class="col-md-6 col-lg-4">
<div class="portfolio-item mx-auto" data-toggle="modal" data-target="#portfolioModal1">
<div class="portfolio-item-caption d-flex align-items-center justify-content-center h-100 w-100">
<div class="portfolio-item-caption-content text-center text-white">
<i class="fas fa-plus fa-3x"></i>
</div>
</div>
<img class="img-fluid" src="{% static 'images/portfolio/cabin.png'%}" alt="">
</div>
</div>
</div>
<!-- /.row -->
</div>
</section>
<!-- About Section -->
<section class="page-section bg-primary text-white mb-0" id="about">
<div class="container">
<!-- About Section Heading -->
<h2 class="page-section-heading text-center text-uppercase text-white">About</h2>
<!-- Icon Divider -->
<div class="divider-custom divider-light">
<div class="divider-custom-line"></div>
<div class="divider-custom-icon">
<i class="fas fa-star"></i>
</div>
<div class="divider-custom-line"></div>
</div>
<!-- About Section Content -->
<div class="row">
<div class="col-lg-12 ml-auto text-center">
<p class="lead">Hi! Im Zeeshan Tariq. I have 3 plus years of experience in web Application Development, Software Development, Front End Development, WordPress theme customization , woocommerce customization, wordpress security, SEO, keywords research, on-page seo, off-page seo,speed optimization, custom web application development using python django web framework, API design, database design and development.</p>
</div>
</div>
</div>
</section>
<!-- Portfolio Modals -->
<!-- add Modal -->
<div class="portfolio-modal modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModal" aria-hidden="true">
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">
<i class="fas fa-times"></i>
</span>
</button>
<div class="modal-body text-center">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-8">
<!-- Portfolio Modal - Title -->
<h2 class="portfolio-modal-title text-secondary text-uppercase mb-0">Add Todo</h2>
<!-- Icon Divider -->
<div class="divider-custom">
<div class="divider-custom-line"></div>
<div class="divider-custom-icon">
<i class="fas fa-star"></i>
</div>
<div class="divider-custom-line"></div>
</div>
<!-- Portfolio Modal - Image -->
<!-- Portfolio Modal - Text -->
<p class="mb-5">
<div class="row">
<div class="col-lg-8 mx-auto">
<form action="{% url 'add'%}" method="post">
{%csrf_token%}
<div class="control-group">
<div class="form-group floating-label-form-group controls mb-0 pb-2">
<label>Title </label>
<input class="form-control" id="addTitle" name="addTitle" type="text" placeholder="Title" required="required" data-validation-required-message="Please enter the title.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="control-group">
<div class="form-group floating-label-form-group controls mb-0 pb-2">
<label>Detail</label>
<input class="form-control" id="addDetail" name="addDetail" type="text" placeholder="Detail" required="required" data-validation-required-message="Please enter the description.">
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-xl" id="sendMessageButton">Add</button>
</div>
</form>
</div>
</div>
</p>
<button class="btn btn-primary" href="#" data-dismiss="modal">
<i class="fas fa-times fa-fw"></i> Close Window
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Portfolio Modal 1 -->
<div class="portfolio-modal modal fade" id="portfolioModal1" tabindex="-1" role="dialog" aria-labelledby="portfolioModal1Label" aria-hidden="true">
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">
<i class="fas fa-times"></i>
</span>
</button>
<div class="modal-body text-center">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-8">
<!-- Portfolio Modal - Title -->
<h2 class="portfolio-modal-title text-secondary text-uppercase mb-0">{{todoItems.title}}</h2>
<!-- Icon Divider -->
<div class="divider-custom">
<div class="divider-custom-line"></div>
<div class="divider-custom-icon">
<i class="fas fa-star"></i>
</div>
<div class="divider-custom-line"></div>
</div>
<!-- Portfolio Modal - Image -->
<img class="img-fluid rounded mb-5" src="img/portfolio/cabin.png" alt="">
<!-- Portfolio Modal - Text -->
<p class="mb-5">{{todoItems.detail}}</p>
<button class="btn btn-primary" href="#" data-dismiss="modal">
<i class="fas fa-times fa-fw"></i> Close Window
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{%include 'footer.html'%}

Integrity Error, UNIQUE constraint failed

I am trying to allow users to upload photos and to be able to change them. Whenever the user comes back and changes the photos I get an Integrity error, "UNIQUE constraint failed: portal_content.user_id". I assume it's that I am trying to save the user when there already is one. The problem with this though is that I do not know how work around around it and fix it. I've seen similar problems, but do to my skill level I am not really sure on how to fix it. Here is my code:
Model:
def content_file_name(instance, filename):
return '/'.join(['content', instance.user.username, filename])
class Content(models.Model):
user = models.OneToOneField(User, unique=True)
image1 = models.ImageField(upload_to=content_file_name, null=True, blank=True)
image2 = models.ImageField(upload_to=content_file_name, null=True, blank=True)
image3 = models.ImageField(upload_to=content_file_name, null=True, blank=True)
image4 = models.ImageField(upload_to=content_file_name, null=True, blank=True)
image5 = models.ImageField(upload_to=content_file_name, null=True, blank=True)
image6 = models.ImageField(upload_to=content_file_name, null=True, blank=True)
image7 = models.ImageField(upload_to=content_file_name, null=True, blank=True)
image8 = models.ImageField(upload_to=content_file_name, null=True, blank=True)
terms = models.ImageField(upload_to=content_file_name, null=True, blank=True)
View:
#login_required
def register(request):
if request.POST:
content = Content()
content.user = request.user
content.image1 = request.FILES.get('image1_upload', None)
content.image2 = request.FILES.get('image2_upload', None)
content.image3 = request.FILES.get('image3_upload', None)
content.image4 = request.FILES.get('image4_upload', None)
content.image5 = request.FILES.get('image5_upload', None)
content.image6 = request.FILES.get('image6_upload', None)
content.image7 = request.FILES.get('image7_upload', None)
content.image8 = request.FILES.get('image8_upload', None)
content.terms = request.POST.get('terms')
content.save()
return redirect('/portal/register')
try:
gallery = Content.objects.get(user=request.user)
return render(request, 'portal/register.html', {'gallery': gallery})
except ObjectDoesNotExist:
print 'Does Not Exist!'
return render(request, 'portal/register.html')
Template:
{% extends 'portal/base.html' %}
{% load staticfiles %}
{% block head_block %}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<script language="javascript" type="text/javascript" src="{% static 'js/input.js' %}"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" type="text/javascript"></script>
{% endblock %}
{% block body_block %}
<div class="container">
<form role="form" method="post" action="." id="js-upload-form" enctype="multipart/form-data">
{% csrf_token %}
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">{{ user.username }}</h1>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" id="image1" src="/media/{{ gallery.image1 }}" alt="">
</a>
<input type="file" name="image1_upload" id="image1_upload" multiple>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" id="image2" src="/media/{{ gallery.image2 }}" alt="">
</a>
<input type="file" name="image2_upload" id="image2_upload" multiple>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" id="image3" src="/media/{{ gallery.image3 }}" alt="">
</a>
<input type="file" name="image3_upload" id="image3_upload" multiple>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" id="image4" src="/media/{{ gallery.image4 }}" alt="">
</a>
<input type="file" name="image4_upload" id="image4_upload" multiple>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" id="image5" src="/media/{{ gallery.image5 }}" alt="">
</a>
<input type="file" name="image5_upload" id="image5_upload" multiple>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" id="image6" src="/media/{{ gallery.image6 }}" alt="">
</a>
<input type="file" name="image6_upload" id="image6_upload" multiple>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" id="image7" src="/media/{{ gallery.image7 }}" alt="">
</a>
<input type="file" name="image7_upload" id="image7_upload" multiple>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" id="image8" src="/media/{{ gallery.image8 }}" alt="">
</a>
<input type="file" name="image8_upload" id="image8_upload" multiple>
</div>
</div>
<br>
<!--<div class="form-group">-->
<!--<textarea name="terms" id="terms" class="form-control input-sm" placeholder="Terms" value="{{ content.terms }}"></textarea>-->
<!--</div>-->
<div class="form-group">
<input type="text" name="terms" id="terms" class="form-control input-sm" placeholder="terms" value="{{ gallery.terms }}">
</div>
<br>
<input type="submit" value="Register" id="js-upload-submit" class="btn btn-info btn-block">
</form>
<br>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
iPad View
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">{{ user.Username }}</h1>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" src="/media/{{ gallery.image1 }}" alt="">
</a>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" src="/media/{{ gallery.image2 }}" alt="">
</a>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" src="/media/{{ gallery.image3 }}" alt="">
</a>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" src="/media/{{ gallery.image4 }}" alt="">
</a>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" src="/media/{{ gallery.image5 }}" alt="">
</a>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" src="/media/{{ gallery.image6 }}" alt="">
</a>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" src="/media/{{ gallery.image7 }}" alt="">
</a>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" src="/media/{{ gallery.image8 }}" alt="">
</a>
</div>
</div>
<p>
{{ gallery.terms }}
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<script language="javascript" type="text/javascript" src="{% static 'js/preview.js' %}"></script>
{% endblock %}
<!--http://jsfiddle.net/Mqvgx/-->
Your register() view attempts to create a new Content object each time. Since every user can only be related to a single Content object, when attempting to create a second one, it will fail.
You could replace content = Content() with a content, created = Content.objects.get_or_create(user=request.user). This would take care of multiple Content objects for a user.
P.S. a much better approach would be to use Django's ModelForms.