django-templates

Writing a Template Tag in Django

青春壹個敷衍的年華 提交于 2019-12-11 09:01:23
问题 I'm trying to customise a CMS written in Django. The content editors aren't flexible enough so I'm trying to come up with a better solution. Without over-explaining it, I'd like it to be a bit like django-better-chunks or django-flatblocks . You set up an editable region entirely from within the template. I want to bind these editable regions to a mix of strings and object instances. One example would be having multiple editable regions based on one product: {% block product_instance "title"

Wildcard searching in Django

蓝咒 提交于 2019-12-11 08:57:09
问题 How can we do a wildcard searching in Django. If i am filtering username from a list in database, how is it possible to display the filtered data with those exact usernames or part of it.? def filter(request): val3='' if request.GET.has_key('choices'): val2=request.GET.get('choices') if request.GET.has_key('textField'): val3=request.GET.get('textField') if request.POST: val2=request.POST.get('choices') val3=request.POST.get('textField') if val2=='Designation': newData = EmployeeDetails

Using the Django Formset to Generate a Dynamic Form from Multiple Models

我只是一个虾纸丫 提交于 2019-12-11 08:28:05
问题 So here is my problem: I'm trying to generate a big form of with a bunch of characteristics, some of them to be ticket it off if they are boolean, some to be filled with text and some to be incremented or decremented with a JS spinner. But, and here is the catch, all of them are user generated. What I did was this: In some point I invite the user to create it's characteristics by adding objects to the model Option, in which he tells me the name of the characteristics and it's type (boolean,

Is there a way to use/bring up a console when viewing templates (using Django Debug Toolbar)?

核能气质少年 提交于 2019-12-11 08:14:26
问题 I love Django Debug Toolbar and I mainly use it just to see the variables passed to the template (shown under the "Templates" tab on the right menu). But the variables are shown like this {'form': <django.forms.models.OrderForm object at 0x1033937d0>} {'csrf_token': <django.utils.functional.__proxy__ object at 0x103394cd0>} {'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x103393510>, 'user': <django.utils.functional.SimpleLazyObject object at 0x10339b690>} {'debug':

displaying unique objects only in django templates

别等时光非礼了梦想. 提交于 2019-12-11 07:51:42
问题 I have a list of objects. I want to display these objects in such a way that only the first unique date displays if the subsequent objects contain the same date. If the date is different than it should display. Here is an example. data: id: 2, date: "01/01/2010" id: 3, date: "01/01/2010" id: 4, date: "02/02/2010" What I want to display: id - 2, "01/01/2010" id - 3, id - 4, "02/02/2010" See how id 3 shows nothing since the previous date was the same? How do I do this with django templates? One

Django - AttributeError => 'set' object has no attribute 'get'

馋奶兔 提交于 2019-12-11 07:31:33
问题 I'm going through the book Django 1.0 Website Development where you build a small social bookmarking application. I'm at chapter 5 where you create a form to add bookmarks and although I've followed the instructions and have been struggling on this error for days. I get the error: AttributeError at /save/ 'set' object has no attribute 'get' The error is being thrown on line 6 of the template {{ form.as_p }} The views.py code is: def bookmark_save_page(request): if request.method == 'POST':

OSMWidget - map doesn't show in template - ReferenceError: ol is not defined

故事扮演 提交于 2019-12-11 07:22:14
问题 I'm trying to display the OSMWidget in a form using generic CreateVIew template. # models.py class Building(models.Model): point = PointField('kort markør', null=True) country = models.CharField('land', max_length=100, blank=True, null=True, default='Danmark') city = models.CharField('by', max_length=100, blank=True, null=True) # views.py from django.contrib.auth.mixins import LoginRequiredMixin from django.urls import reverse_lazy from django.views.generic import ListView, CreateView,

Django form - type of variable changes when reloaded after validation error

江枫思渺然 提交于 2019-12-11 07:06:54
问题 I have spent some time on this but cannot figure out the exact cause of the following behaviour. I have a Django form and in the template I am trying to see if an integer is present in a list and then doing something with it. {% if pk in form.area.value %} {# form.area.value is a list like [7,21] #} do something {% endif%} Everything works fine except in cases where the form is reloaded after a validation error. In such cases, the list that I am comparing with, gets converted to list of

Change HTML with variables in Django

独自空忆成欢 提交于 2019-12-11 07:06:29
问题 I have the dict latest_status: {'What': 10, "Study'": 10, 'all': 10, 'to': 10, "facebook'": 10, 'has': 10, 'worth': 20, 'hurting': 10 } I am trying to make a text cloud by doing something like this in my template: {% for word,count in latest_status.items %} <style="font-size:{{ count }}px"> {{ word }}</style> {% endfor %} I am trying to manipulate the font size with the count from the dict but it doesn't seem to be working. 回答1: The <style> tag is used to introduce a block (or external

How to display text with HTML-markup? (I use ckeditor)

天涯浪子 提交于 2019-12-11 06:50:58
问题 I heard about the filter |safe , but if I understood correctly, that's unsafe and creates a backdoor for injections. What are the alternatives to display full posts with formatted text? 回答1: I think when you not use the filter of |safe , then output should return as text only with html markup (not rendered as html output) . But, if you need to exclude some dangerous tags such as <script>location.reload()</script> , you need to handle it with custom templatetag filter.. I got good answer from: