{% recursetree categories %}
<!-- блок аккордеон -->
<div class="accordion">
<section class="accordion_item">
<h3 class="title_block"><strong>{{ node.name }}</strong></h3>
{% if not node.is_leaf_node %}
{% for child in node.children.all %}
<div class="info"><hr>
<ul>
<li class="info_item"><a href="{% url 'shop:catlist' child.slug %}"><u>{{ child.name }}</u></a></li>
</ul>
{% recursetree child.children.all %}
<ul>
<li class="info"><a href="{% url 'shop:shop-list' node.slug %}">{{ node.name }}</a></li>
</ul>
{% endrecursetree %}
</div>
{% endfor %}
{% endif %}
</section>
</div>
<!-- конец блока аккордеон -->
{% endrecursetree %}
<script type="text/javascript">
var img = document.getElementById("display-1").getElementsByTagName("img")[0]; //получаем большую картинку.
function changeIMG(str){
img.setAttribute('src', str);
}
</script>
на <a> повесить обработчик onclick = "changeIMG('/новый адрес для картинки/')"
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '',
'USER': '',
'PASSWORD': '',
'OPTIONS': {
"init_command": "SET storage_engine=MYISAM",
}
}
},
# -*- coding: UTF-8 -*-
from django import forms
#from django.forms import ModelForm
# from mystudio.models import MailBox
class ContactForm(forms.Form):
subject = forms.CharField(max_length=100)
sender = forms.EmailField()
#phone = forms.CharField(max_length=15)
message = forms.CharField()
copy = forms.BooleanField(required=False)
def contact(reguest):
if reguest.method == 'POST':
form = ContactForm(reguest.POST)
# Если форма заполнена корректно, сохраняем все введённые пользователем значения
if form.is_valid():
subject = form.cleaned_data['subject']
sender = form.cleaned_data['sender']
#phone = form.cleaned_data['phone']
message = form.cleaned_data['message']
copy = form.cleaned_data['copy']
recepients = ['myemail@mail.ru']
# Положим копию письма в базу данных
#MailBox.objects.create(subject=subject, sender=sender, phone=phone, message=message, copy=copy)
# Если пользователь захотел получить копию себе, добавляем его в список получателей
if copy:
recepients.append(sender)
try:
send_mail(subject, message, 'myemail@mail.ru', recepients)
except BadHeaderError: #Защита от уязвимости
return HttpResponse('Invalid header found')
# Переходим на другую страницу, если сообщение отправлено
return redirect('/mystudio/thanks/')
else:
form = ContactForm()
# Выводим форму в шаблон
return render(reguest, 'mystudio/contact.html', {'form': form})
def category(reguest, slug):
context_dict = {}
try:
category = Category.objects.get(slug=slug)
context_dict['category_name'] = category.name
object = BlogPost.objects.filter(category=category)
paginator = Paginator(object, 2)
try:
page = request.GET.get('page')
except:
page = 1
try:
objects = paginator.page(page)
except(EmptyPage, InvalidPage):
objects = paginator.page(paginator.num_pages)
context_dict['objects'] = objects
context_dict['category'] = category
context_dict['pages'] = paginator.page(page)
except Category.DoesNotExist:
pass
return render(reguest, 'category.html', context_dict)
<div class="row">
<div class="col-lg-12" align="center">
<ul class="pagination">
{% if objects.has_previous %}
<li class="arrow"><a href="/blog/category/{{ objects.previous_page_number }}/">«</a></li>
{% else %}
<li class="disabled"><a href="">«</a></li>
{% endif %}
{% for pag in objects.paginator.page_range %}
{% if pag == objects.number %}
<li class="active"><a href="/blog/category/{{ category.slug }}/?page={{ pag }}">{{ pag }}</a></li>
{% else %}
<li><a href="/blog/category/{{ category.slug }}/?page={{ pag }}">{{ pag }}</a></li>
{% endif %}
{% endfor %}
{% if objects.has_next %}
<li class="arrow"><a href="/blog/category/{{ objects.next_page_number }}/">»</a></li>
{% else %}
<li class="disabled"><a href="">»</a></li>
{% endif %}
</ul>
</div>
</div>
url(r'^category/(?P<slug>[-\w]+)/$', views.category, name='category'),
def category(reguest, slug):
category = Category.objects.get(slug=slug)
post = BlogPost.objects.filter(category=category)
paginator = Paginator(post, 2)
page = reguest.GET.get('page')
try:
post = paginator.page(page)
except PageNotAnInteger:
post = paginator.page(1)
except EmptyPage:
post = paginator.page(paginator.num_pages)
return render(reguest, 'category.html', {
'category': category,
'page': page,
'post': post})
<div class="row">
<div class="col-lg-12" align="center">
<ul class="pagination">
{% if post.has_previous %}
<li class="arrow"><a href="/blog/category/{{ category.slug }}?page={{ pag }}{{ post.previous_page_number }}">«</a></li>
{% else %}
<li class="disabled"><a href="">«</a></li>
{% endif %}
{% for pag in post.paginator.page_range %}
{% if pag == post.number %}
<li class="active"><a href="/blog/category/{{ category.slug }}?page={{ pag }}">{{ pag }}</a></li>
{% else %}
<li><a href="/blog/category/{{ category.slug }}?page={{ pag }}">{{ pag }}</a></li>
{% endif %}
{% endfor %}
{% if post.has_next %}
<li class="arrow"><a href="/blog/category/{{ category.slug }}?page={{ pag }}{{ post.next_page_number }}">»</a></li>
{% else %}
<li class="disabled"><a href="">»</a></li>
{% endif %}
</ul>
</div>
</div>
url(r'^category/(?P<slug>[-\w]+)/$', views.category, name='category'),