django-templates

Why my ajax function are not working on infinite scrolling?

好久不见. 提交于 2020-07-09 13:53:39
问题 I am building a webpage having infinite scroll using waypoints.js with backend as Django.The problem is, my jquery and ajax functions are not working on newly generated content while they are working with content on first page. **EDIT:-**I am updating my code so that it will be easier to undertsand my question. <div class="infinite-container"> {%if result %} {% for c in result %} <div class="infinite-item"> <img class="likebutton" value="{{c.id}}" id="{{c.id}}" src="{%static "/images/icons

Why my ajax function are not working on infinite scrolling?

感情迁移 提交于 2020-07-09 13:52:06
问题 I am building a webpage having infinite scroll using waypoints.js with backend as Django.The problem is, my jquery and ajax functions are not working on newly generated content while they are working with content on first page. **EDIT:-**I am updating my code so that it will be easier to undertsand my question. <div class="infinite-container"> {%if result %} {% for c in result %} <div class="infinite-item"> <img class="likebutton" value="{{c.id}}" id="{{c.id}}" src="{%static "/images/icons

Sprinkling VueJs components into Django templates

时光怂恿深爱的人放手 提交于 2020-07-09 11:54:54
问题 I'm working on a Django site and I'm looking to "sprinkle" in some Vue components to the Django rendered templates. I'm working in a single repository and have webpack setup to create style/js bundles that I use within the Django templates. I'm struggling to get the functionality working how I'd like it, mainly regarding renderless Vue components, since I want to handle all (or at least the vast majority) of html within the Django templates and just use Vue components for some logic in some

Django: django-autocomplete-light does not work properly

回眸只為那壹抹淺笑 提交于 2020-07-08 10:51:32
问题 I'm using django-autocomplete-light in django 1.8. But I don't know how to use it in forms.py . Instead of autocomplete field I see a select field. I followed the instructions from here. In models.py I have: class icd_10(models.Model): id = models.IntegerField(unique=True,primary_key=True,null=False,blank=False) icd_10_desc = models.CharField('ICD-10 description',max_length=80,null=True,blank=True) icd_10_code = models.CharField('ICD-10 code',max_length=10,null=True,blank=True) def __str__

Django: django-autocomplete-light does not work properly

拈花ヽ惹草 提交于 2020-07-08 10:51:06
问题 I'm using django-autocomplete-light in django 1.8. But I don't know how to use it in forms.py . Instead of autocomplete field I see a select field. I followed the instructions from here. In models.py I have: class icd_10(models.Model): id = models.IntegerField(unique=True,primary_key=True,null=False,blank=False) icd_10_desc = models.CharField('ICD-10 description',max_length=80,null=True,blank=True) icd_10_code = models.CharField('ICD-10 code',max_length=10,null=True,blank=True) def __str__

Django template query for loop render taking too much time

孤者浪人 提交于 2020-06-29 05:07:18
问题 I have a related query of limit 10 of an object. It's taking over 9s to load the whole page in development mode. When I'm not running the related query for loop on template, it only takes 1s to load. I'm quite confused what's going on in here! Please help me identify the problem/what I'm doing wrong here! Thanks in advance! Here' my view file code - related = News.objects.filter( is_active=True, status='public', language=request.LANGUAGE_CODE, category=news.category ).order_by('-published_at'

Django template query for loop render taking too much time

你说的曾经没有我的故事 提交于 2020-06-29 05:07:17
问题 I have a related query of limit 10 of an object. It's taking over 9s to load the whole page in development mode. When I'm not running the related query for loop on template, it only takes 1s to load. I'm quite confused what's going on in here! Please help me identify the problem/what I'm doing wrong here! Thanks in advance! Here' my view file code - related = News.objects.filter( is_active=True, status='public', language=request.LANGUAGE_CODE, category=news.category ).order_by('-published_at'

Django 3.0 images: Unable to display images in template

大兔子大兔子 提交于 2020-06-29 05:04:35
问题 I have model named Book in models.py file. And based on this model, a view has been created to display images as products. Which renders books(products) on shop.html template. Problem is that i am unable to get their cover images which are saved across each publishers id who is seller of those books. This is code of shop.html (in which i am trying to display image). <div class="container mt-4"> <div class="row"> {% for b in books|slice:":10" %} <div class="col-lg-2 col-md-3 col-sm-4"> <div

How to select a random image in a Django template?

好久不见. 提交于 2020-06-29 03:23:29
问题 I currently have an image in a Django template which I would like to choose randomly every time the page is loaded: <!--<img src="{% static 'images/640px-Waaah.jpg' %}"/>--> <img src="{% static 'images/Crying_Baby.jpg' %}"/> I've found some custom filters on Github for this purpose (e.g. random_image), but it seems to me like this should be possible using the built-in tags, in particular, the random filter. It would be something like {% with ['images/640px-Waaah.jpg', 'images/Crying_Baby.jpg'

Django. How to reduce total number of coupons after each use

时光毁灭记忆、已成空白 提交于 2020-06-27 08:15:07
问题 Hey guys I am learning to develop a ecommerce website, I have a coupon model with used and max_value, which take care of max number of coupon available to use, I want to implement that in my views, such that if the coupon is redeemed more than the max_value(number of coupons), then it should show an error message. Whatever I have tried with my limited knowledge is resulting in errors. How can I increment the 'used' in views? This is in much more understandable way: users(sellers) are able to