Django URL pattern does not match with my config - django-templates

I'm new with Django, I'm having a problem with the url of the page "DetailLivre.html" it shows :
Using the URLconf defined in Ilhem.urls, Django tried these URL patterns, in this order:
^Bibliotheque/ ^$ [name='index']
^Bibliotheque/ ^(?P<livre_id>[0-9]+)/$ [name='DetailLivre']
^admin/
The current URL, Bibliotheque/BOOK1/, didn't match any of these.*
I'm using: Python 2.7.6, django 1.8.5 can you please help?
index.html:
<h1>La liste des Livres </h1>
{% block content %}
{% block theme %}
{% load bootstrap_themes %}
{% bootstrap_styles theme='default' type='min.css' %}
{% bootstrap_styles theme='cosmo' type='css' %}
{% bootstrap_styles theme='united' type='less' %}
{% bootstrap_script use_min=True %}
{% endblock theme %}
{% if BookList%}
<div class="container-fluid">
<div class="row">
<ul>
{% for livre in BookList %}
<li>{{ livre.Titre }}</li>
{% endfor %}
</ul>
</div>
</div>
{% else %}
<p>Pas de Livres.</p>
{% endif %}
{% endblock %}
DetailLivre.html
<h1>{{ Auteur }}</h1>
<label for="Nom">{{ Auteur.Nom }}</label><br />
<label for="Prenom">{{ Auteur.Prenom }}</label><br />
<label for="dateNaissance">{{ Auteur.dateNaissance }}</label><br />
<label for="Lieu_de_naissance">{{ Auteur.Lieu_de_naissance }}</label><br />
<label for="Specialite">{{ Auteur.Specialite }}</label>
Views.py
from django.shortcuts import render
from django.template import RequestContext, loader
from django.http import HttpResponse
from django.template import RequestContext, loader
from django.shortcuts import get_object_or_404, render
from .models import Livre, Auteur
def index(request):
BookList = Livre.objects.all()
template = loader.get_template('Bibliotheque/index.html')
context = RequestContext(request, {
'BookList': BookList,
})
return HttpResponse(template.render(context))
def DetailLivre(request, livre_id):
livre = Livre.objects.get(pk=livre_id)
return render(request, 'Bibliotheque/DetailLivre.html', {'livre.Titre': livre.Titre})
url.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^(?P<livre_id>[0-9]+)/$', views.DetailLivre, name='DetailLivre'),
]

you have missing BOOK prefix BOOK(?P<livre_id>[-\d]+)

Related

Out Of Stock Products Showing Incorrect Price - Shopify

I am using an app name "Multi country pricing" through which I am showing different prices by location. The app is using products variants for showing different prices by location. Now the problem is prices are showing incorrect when item is out of stock. I have done what I could do but nothing helped. Please help me sort this issue as it's so frustrating. Thanks in advance
Here is the screenshot of my product
reference screenshot
here's my product-template. liquid code
{% unless settings.breadcrumb_styles == 'none' %}{% include 'breadcrumb' %}{% endunless %}
<div itemscope itemtype="http://schema.org/Product">
<meta itemprop="image" content="https:{{ product.featured_image.src | product_img_url: 'grande' }}">
<span itemprop="name" class="hide">{{ product.title }}</span>
<meta itemprop="mpn" content="925872" />
<meta itemprop="brand" content="{{ product.vendor }}">
<meta itemprop="sku" content="{{ product.variants.first.sku }}">
<div itemprop="aggregateRating"
itemscope itemtype="http://schema.org/AggregateRating" style="display: none;">
Rated <span itemprop="ratingValue">3.5</span>/5
based on <span itemprop="reviewCount">11</span> customer reviews
</div>
<meta itemprop="description" content="{{ product.description | strip_html | truncate: 100 }}">
{% assign _lazyload = settings.use_lazyload %}
{% assign _product_layout = 'normal' %}
{% assign _main_class = 'col-12' %}
<div class="container">
<div id="col-main" class="page-product layout-{{ _product_layout }} slider-normal">
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<meta itemprop="url" content="{{ shop.url }}{{ product.url }}" />
{% if product.available %}
<link itemprop="availability" href="https://schema.org/InStock" />
{% else %}
<link itemprop="availability" href="https://schema.org/OutOfStock" />
{% endif %}
<div class="product">
<div class="product-content-wrapper">
<div class="row">
<div class="col-lg-7 col-md-6 col-sm-12 col-12">
{% include 'product-detail-image' %}
</div>
<div class="col-lg-5 col-md-6 col-sm-12 col-12">
<div id="product-info" class="product-info" data-stock="{{ section.settings.show_product_quantity }}">
<div class="product-info-inner">
{% include 'product-detail-discount-popup' %}
<div class="d-flex brand-label">
{% if section.settings.show_product_vendor and product.vendor != blank %}
<div class="product-vendor">{{ product.vendor | link_to_vendor }}</div>
{% endif %}
{% include 'product-label' %}
</div>
<h1 itemprop="name" content="{{ product.title }}" class="page-heading">{{ product.title }}</h1>
{% include 'product-detail-review' %}
{% include 'product-detail-price' %}
{% include 'product-detail-short-description' %}
{% include 'product-detail-sku-stock' %}
{% include 'product-detail-inventory' %}
{% include 'product-detail-deals' %}
{% if product.available %}
{% assign hide_default_title = false %}
{% if product.variants.size == 1 and product.variants.first.title contains 'Default' %}
{% assign hide_default_title = true %}
{% endif %}
<div class="group-cw clearfix">
{% form 'product', product, class:'product-form product-action variants' %}
{% include 'product-detail-variants' %}
<div class="qty-add-cart">
{% include 'product-detail-qty' %}
{% include 'product-detail-btn' %}
</div>
{% endform %}
{% include 'layout-people-in-cart' %}
{% include 'product-detail-order-shipping' %}
{% include 'product-detail-pre-order-btn' %}
{% include 'product-detail-wishlist-compare' %}
</div>
{% else %}
{% include 'product-detail-unavailable' %}
{% endif %}
{% comment %} {% include 'product-detail-short-description' %} {% endcomment %}
{% include 'product-detail-popup' %}
{% include 'product-detail-pre-order' %}
{% include 'product-secure-image' %}
{% if settings.show_social_sharing_product and settings.share_js != blank %}
{% include 'social-sharing' %}
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% include 'product-toggle' %}
{% if section.settings.product_tab_review == 'below' and settings.product_review_option != 'none' %}
<div class="review-item" id="tab_review_tabbed">
<div id="tab-review" class="container">
{% include 'product-detail-review-content' %}
</div>
</div>
{% endif %}
{% for block in section.blocks %}
{% case block.type %}
{% when 'related-product' %}
{% include 'related-product' %}
{% when 'super-deals-product' %}
{% include 'super-deals-product' %}
{% when 'article' %}
{% include 'category-top-article' %}
{% else %}
{% endcase %}
{% endfor %}
</div>
{% if settings.enable_notify_product_page %}
{% include 'layout-notify' %}
{% endif %}
{% include 'product-template-script' %}
And here's my product-template-script. liquid code
<script type="application/json" id="VariantJson-{{ section.id }}">
[
{% for variant in product.variants %}
{
"id":{{ variant.id | json }},
"incoming": {{ variant.incoming | default: false | json }},
"unformat_incoming_date": {{ variant.next_incoming_date | date:"%d/%m/%Y" | json }},
"next_incoming_date": {{ variant.next_incoming_date | date: format: 'month_day_year' | json }},
"inventory_policy": {{ variant.inventory_policy | json }},
"inventory_quantity": {{ variant.inventory_quantity | json }}
}{% unless forloop.last %},{% endunless %}
{% endfor %}
]
</script>
<script type="text/javascript">
jQuery(document).ready(function($) {
{% unless template.suffix == 'redirect' %}AT_Main.stickAddToCart();{% endunless %}
AT_Main.deadLine_time();
AT_Main.delivery_time();
AT_Main.scrollToReview();
jQuery('.panel-product-accordion .panel-title > a').on('click',function (e) {
$('.panel-product-accordion .panel-collapse').removeClass('show');
$(this).parents('.panel-product-accordion').first().find('.panel-collapse').addClass('show');
})
});
// initialize multi selector for product
$(window).on('load', function () {
setTimeout(function(){
AT_Main.scareWidth();
}, 1000);
$(".qty-inner .qty-up").on("click", function() {
var oldValue = $("#quantity").val(),
newVal = 1;
newVal = parseInt(oldValue) + 1;
$("#quantity").val(newVal);
});
$(".qty-inner .qty-down").on("click", function() {
var oldValue = $("#quantity").val();
if (oldValue > 1) {
newVal = 1;
newVal = parseInt(oldValue) - 1;
$("#quantity").val(newVal);
}
});
var variantProd = JSON.parse(jQuery('#VariantJson-{{ section.id }}').html());
/* selectCallback */
var selectOptionsCallback = function(variant, selector) {
if (variant) {
var form = jQuery('#' + selector.domIdPrefix).closest('form');
for (var i=0,length=variant.options.length; i<length; i++) {
var radioButton = form.find('.swatch[data-option-index="' + i + '"] :radio[value="' + variant.options[i] +'"]');
if (radioButton.length) {
radioButton.get(0).checked = true;
}
}
}
var add_to_cart = '#add-to-cart';
var $price = '#purchase-' + selector.product.id.toString() + ' .detail-price';
if (jQuery('#product-info.product-info').data('stock')) {
if (variant) {
var variant_stock = variantProd.find(item => item.id === variant.id);
if (variant.available) {
$('.inventory-quantity').removeClass('hide');
if(variant_stock.inventory_quantity > 0){
$('.inventory-quantity .text .number').html('<span class="number">' + variant_stock.inventory_quantity + '</span>')
var _total_inventory_quantity = variant_stock.inventory_quantity + 5;
}
else{
$('.inventory-quantity .text .number').html('<span class="number">5</span>')
var _total_inventory_quantity = 10;
}
var _percent = (5/_total_inventory_quantity)*100;
$('.inventory-quantity .line2').css('width', _percent + '%');
}
else{
$('.inventory-quantity').addClass('hide');
}
}
}
if (variant && variant.available) {
jQuery("#stock").html('<span>{{"products.product.available" | t }}:</span><span class="stock"> {{"products.product.in_stock" | t }}</span>');
// Update variant image
if (variant.featured_image) {
var originalImage = jQuery(".slider-for-00 .slick-current .image-zoom");
var newImage = variant.featured_image;
var element = originalImage[0];
var groupImage = String(variant.featured_image.alt);
AT_Main.productPage_variantFilter(groupImage == 'null' ? 'none-group' : groupImage);
Shopify.Image.switchImage(newImage, element, function (newImageSizedSrc, newImage, element) {
jQuery('.slider-thumbs-00 img').each(function() {
var grandSize = jQuery(this).attr('src');
grandSize = grandSize.replace('small','2048x2048');
if (grandSize == newImageSizedSrc) {
jQuery(this).parent().trigger('click');
let w_thumb = jQuery('.slider-thumbs-00').outerWidth()
,w_track = jQuery('.slider-thumbs-00 .slick-track').outerWidth();
if ((w_track <= w_thumb || AT_Main.getWidthBrowser() < 768)) {
jQuery('.slider-thumbs-00 .slick-track').addClass('no-translate3d');
}else{
jQuery('.slider-thumbs-00 .slick-track').removeClass('no-translate3d');
}
return false;
}
});
});
}
// selected a valid variant
$(add_to_cart).removeClass('disabled').removeAttr('disabled').html('<span class="demo-icon icon-electro-add-to-cart-icon"></span>{{ "products.product.add_to_cart" | t }}'); // remove unavailable class from add-to-cart button, and re-enable button
if(variant.compare_at_price == null){
$($price).html('<span class="price">'+Shopify.formatMoney(variant.price, '{{shop.money_format}}')+'</span>');
jQuery(".brand-label .label-sale").addClass('hide');
}
else {
$($price).html('<del class="price-compare">'+Shopify.formatMoney(variant.compare_at_price, '{{shop.money_format}}') + '</del>' + '<span class="price-sale">' + Shopify.formatMoney(variant.price, '{{shop.money_format}}') + '</span>');
jQuery(".brand-label .label-sale").removeClass('hide');
}
{% if section.settings.enable_pre_order_button %}
$('.shopify-payment-button').removeClass('hide');
{% endif %}
/* Update currency */
{% if settings.currency_type == '2' %}
currenciesCallbackSpecial('#product-info span.money');
{% endif %}
}
else {
jQuery("#stock").html('<span>{{"products.product.available" | t }}:</span><span class="stock"> {{"products.product.out_stock" | t }}</span>');
$(add_to_cart).addClass('disabled').attr('disabled', 'disabled'); // set add-to-cart button to unavailable class and disable button
var message = variant ? "{{'products.product.sold_out' | t }}" : "{{'products.product.unavailable' | t }}";
$(add_to_cart).html(message);
{% if section.settings.enable_pre_order_button %}
$('.shopify-payment-button').addClass('hide');
{% endif %}
}
{% if section.settings.show_product_sku %}
if (variant && variant.sku ) { jQuery("#sku").html(variant.sku).parent().show(); }
else{jQuery("#sku").parent().hide(); }
{% endif %}
};
{% if product.variants.size > 0 %}
new Shopify.OptionSelectors("product-select-{{ product.id }}", { product: {{ product | json | remove:'\u003E' | remove:'\u003C' | remove:'\u00a0' }}, onVariantSelected: selectOptionsCallback, enableHistoryState: true });
{% endif %}
// Add label if only one product option
{% if product.options.size == 1 and product.options.first != 'Title' %}
$('.selector-wrapper:eq(0)').prepend('<label>{{ product.options.first | escape }}</label>');
{% endif %}
// Hide selectors if we only have 1 variant and its title contains 'Default'.
{% if product.variants.size == 1 and product.variants.first.title contains 'Default' %}
$('.selector-wrapper').hide();
{% endif %}
});
</script>

Trying to target only frontpage collection to apply a style(Shopify)

OK, so I had asked a few weeks ago on the Shopify forum(slow responses) how to target just one product on a collection page so that there is no hover affect, but now I only want to target the frontpage collection and not my many other collection pages on the site.
Theme is Masonry and here is a snipet of the code I'm working with:
{% if settings.prod_block_display contains 'hover' %}
{% unless forloop.index == 1%}
<div class="hoverinfo{% if forloop.index == 1 %}no-overlay {% endif %}">
<a href="{{ product_url }}">
<div class="info-box">
<div class="title">{{ product-block.title }}</div>
<div class="price">
{% if product-block.compare_at_price_max > product-block.price %}
<span class="previously">{{ product-block.compare_at_price_max | money }}</span>
{% endif %}
{% if product-block.price_varies %}<span class="from">{{ 'products.listing.from' | t }}</span>{% endif %}
<span class="actual">{{ product-block.price | money }}</span>
</div>
</div>
</a>
</div>
{% endunless %}
{% endif %}
{% if settings.prod_block_qv and no_quick_buy == false %}
{% unless forloop.index == 1 %}
<div class="quick-buy-row{% if forloop.index == 1%}no-overlay {% endif %}">
{{ 'products.listing.quick_view' | t }}
</div>
{% endunless %}
{% endif %}
The "{% unless forloop.index == 1%}
" codes are the effects I only want to apply to the frontpage. Any help would be great!
You can add {{ collection.handle }} to classes of product divs where you want to apply the effect. Then in styles.css.liquid add a style for the collection handle (collection.handle) class as required.
What #HymnZ was trying to point to was that you can do things like in styles.liquid.css:
.frontpage .hoverinfo{
display:none;
}
and then in your template:
<div class="{{collection.handle}}">
<div class="hoverinfo">
...
</div>
</div>
This is the easiest way to use this strategy. What I was trying to add on was that you can potentially also use prefixes and suffixes on classes that concatenate with handles to offer more functionality. In styles:
.hide{
display:none;
}
.frontpage-show{
display:block;
}
and then in your template:
<div class="hide {{collection.handle}}-show">
Since most browsers support stacked selectors you probably don't need the -hide, -show variants but they can be helpful depending on how your mind works these things out. The sample above can be used to show/hide things for a variety of circumstances. e.g. you could target elements for a variety of collections:
.frontpage-show,
.collection1-show,
.frontpage.hide, /* these second two are the stacked equivalents to the -show variants */
.collection1.hide{
display:block;
}
Of course you can also do much of this in liquid itself:
{% assign showFor = "frontpage,collection1" |split ','%}
{% if showFor contains collection.handle %}
<div>Something limited</div>
{% endif %}
or
{% assign showFor = "frontpage,collection1" |split ','%}
<div class="{% if showFor contains collection.handle %}conditional{% endif %}">
Something limited
</div>

Django template inheritance the other way round

Django template system lets you easily specify a template and fill it with different data using extends and blocks.
What I need to do is to have several templates, filled with the same data (blocks) while avoiding code repetition. It sounds like a usecase for templatetags but consider this example:
<div class="container">
{% get_tags page as tags %}
{% if tags %}
<div class="ribbon">
<span class="ribbon-inner">{{ tags|join:' | ' }}</span>
</div>
{% endif %}
</div>
If I wanted to display the tags in another template using a different html elements/classes I would have to create at least two templatetags (has_tags and get_tags) or include html in templatetags code.
I'd like to have something like this:
#common.html
{% block tags %}
{% get_tags page as tags %}
{% if tags %}
<div class="ribbon">
<span class="ribbon-inner">{{ tags|join:' | ' }}</span>
</div>
{% endif %}
{% endblock %}
#template_A.html
{% include common.html %}
<div class="container-1">
{% block tags %}
{{ block.super }}
{% endblock %}
</div>
#template_B.html
{% include common.html %}
{% block tags %}
{% get_tags page as tags %}
{{ tags|join:', ' }}
{% endblock %}
The problem is that include renders the template first, therefore it doesn't work this way. There are a lot of similar points in the file I'm editing, so creating and including template for each of them is not a great solution either.
Any thoughts?
Well, this is my solution:
#templateA.html
{% include "_common.html" with parent_file="_templateA.html" %}
#templateB.html
{% include "_common.html" with parent_file="_templateB.html" %}
#_templateA.html
<i>{% block tags %}{% endblock %}</i>
#_templateB.html
<b>{% block tags %}{{ tags|join:' & ' }}{% endblock %}</b>
#_common.html
{% extends parent_file %}
{% block tags %}
{% if not block.super %} # this does the trick
{{ tags|join:' I ' }}
{% else %}
{{ block.super }}
{% endif %}
{% endblock %}
This allows having HTML templates in _templateA.html and _templateB.html. If the block is left empty, it is filled with default from _common.html, while it can be overriden in _template.
It would be nice to override the block tag to avoid code repetition in _common.html but the following implementation fails on block.super() because of missing context.
#register.tag('overridable_block')
def overridable_block(parser, token):
from django.template.loader_tags import do_block
block = do_block(parser, token)
if block.super():
return block.parent
return block
Haven't found a way past this yet.

Shopify Liquid: If Statement

I am trying to enable a div class based on when a user views certain web page eg: blog, index or ../page/webpage
The code is like this:
{% unless template contains "index" and settings.slideshow_enabled %}
<div class="container main content">
{% endunless %}
That "container main content" shows an image behind the nav bar. On other pages, the image starts from below the nav bar. A clear example here: http://retina-theme.myshopify.com/
I want to have that same homepage, link the link above, on selected pages or template:
{% if template == "index" and template == "page" and settings.slideshow_enabled %}
<div class="container main content">
{% endif %}
So far nothing I have tried worked. Any tips?
Edited:
I can't answer my own question as yet but this worked with a tweak to the javascript:
{% unless template contains "page" or template contains "index" and settings.slideshow_enabled %}
<div class="container main content">
{% endunless %}
Multiple conditions in if statements don't work so well in liquid. See a similar question here.
One option is to use nested if statements:
{% if template == "index" or template == "page" %}
{% if settings.slideshow_enabled %}
<div class="container main content">...</div>
{% endif %}
{% endif %}
Or something like this:
{% if template == "index" or template == "page" %}
{% assign correct_template = true %}
{% endif %}
{% if correct_template and settings.slideshow_enabled %}
<div class="container main content">...</div>
{% endif %}

null value when using Dojo datagrid formatter function

I am trying to use a formatter to format dates in a dojo grid with DOJANGO.
This is the template script:
{% extends "dojango/base.html" %}
{% load dojango_grid %}
{% block dojango_page_title %} Testing datagrid {% endblock %}
{% block dojango_header_extra %}
<script type="text/javascript">
function formatDate(datum) {
var d = dojo.date.stamp.fromISOString(datum);
return dojo.date.locale.format(d, {formatLength: 'long'});
}
</script>
<script>
dojo.require("dojo.parser");
dojo.require("dijit.Dialog");
dojo.require("dojo.date.stamp");
dojo.require("dojo.date.locale");
</script>
{% endblock %}
{% block dojango_content %}
<h1> Movimientos </h1>
</br>
</br>
{% datagrid voucher_v1 Movimiento %}
width="100%"
height="500px"
formatter= {'fecha_cambio_saldo':"this.formatDate",'fecha_cambio_saldo_anterior':"this.formatDate"}
id="test_grid"
{% enddatagrid %}
{% endblock %}
However, the function parameter datum is passed null and there is an exception at the line:
return dojo.date.locale.format(d, {formatLength: 'long'});
(it complains that ObjectDate.getHours() is undefined since ObjectDate is null)
What am I missing something here? I followed the example from this link:
Thank you in advance!
Try adding the script
function formatDate(datum) {
var d = dojo.date.stamp.fromISOString(datum);
return dojo.date.locale.format(d, {formatLength: 'long'});
}
after the dojo requires statements