django-templates

django checkbox select all

丶灬走出姿态 提交于 2019-12-08 18:37:27
how can i select all checkbox when i click header checkbox? By javascript? How? And can i do that in easier method? thanks:D run.html <form name="form" method="post" action="/home/{{build}}/"> <br> <input type="submit" value="Delete" style="margin-left:149px; width:80px; height:30px"> <input type="hidden" name="build_id" value="{{build_id}}" /> <table border="1"; style="margin-left:150px; border-collapse:collapse;margin-top:10px"; cellpadding="4" borderColor=black> <tr bgcolor=#888888> <td><input type="checkbox" align="center"></td> <td><b>Run</b></td> <td><b>Product</b></td> </tr> {% for run

Django admin custom template for a particular model

北城余情 提交于 2019-12-08 18:03:36
问题 I'm trying to add a custom template for a particular model in Django admin. Basically I want to show up the Google map for address model in Django-admin. So any help on that? 回答1: This is fully covered in the FineManual(tm) so please read this first. Check this urls: https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#overriding-admin-templates https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#custom-template-options and come back if you have any problem. 来源: https:/

how to organize JS files in Django?

廉价感情. 提交于 2019-12-08 17:43:20
问题 I am currently working with a Django project, I include different libraries JS and I create JS files for manage the other libraries, but I don't know the correct organization of JS files for each html page, for example, I have a "Main.js" and "Milk.js" in base template but I don't want have both files in the same base template, I want separate files for each page.. I tried adding as a normal js file <script src="{{ STATIC_URL }}js/milk.js"></script> But it show me a error message asking me

Change the name attribute of form field in django template using

坚强是说给别人听的谎言 提交于 2019-12-08 16:55:26
问题 I have form field {{form.item}} which will render to <input type="text" name="item" > How can i change the name attribute of the form field using custom template tags? I tried by sending the form to template tag where form.fields['item'].widget.attrs['name'] = 'new_name' But I'm not getting success. I need to change the name attribute in template. UPDATE models.py class A(models.Model): name = models.CharField(50) type = models.CharField(50) class B(models.Model): field1 = ForeignKeyField(A)

Django TemplateTag evaluating to a boolean

烈酒焚心 提交于 2019-12-08 16:53:47
问题 Is it possible to create a Django template tag which evaluates to a boolean? Eg, can I do: {% if my_custom_tag %} .. {% else %} .. {% endif %} At the moment I've written it as an as tag, which works fine like this: {% my_custom_tag as var_storing_result %} But I was just curious if I could do it the other way as I think it'd be nicer if I didn't have to assign the result to a variable first. Thanks! 回答1: You'd have to write a custom {% if %} tag of some sort to handle that. In my opinion, it

How to thumbnail static files?

断了今生、忘了曾经 提交于 2019-12-08 16:15:53
问题 I want to resize my static files with sorl thumbnail but it doesnt work here is my codes {% if not new.photo %} {% with path="{{STATIC_URL}}/images/empty-news.jpg" %} {% thumbnail path "80x80" crop="center" as im %} <a href="#" class="image"><img alt="" src="{{im.url}}" class="frame2"></a> {% endthumbnail %} {% endwith %} {% else %} {% thumbnail new.photo "80x80" crop="center" as im %} <a href="{% url news_detail new.slug %}" class="image"> <img alt="" src="{{im.url}}" class="frame2"></a> {%

Django – remove trailing zeroes for a Decimal in a template

社会主义新天地 提交于 2019-12-08 16:12:05
问题 Is there a way to remove trailing zeros from a Decimal field in a django template? This is what I have: 0.0002559000 and this is what I need: 0.0002559 . There are answers suggesting to do this using the floatformat filter: {{ balance.bitcoins|floatformat:3 }} However, floatformat performs rounding (either down or up), which is unwanted in my case, as I only need to remove trailing zeros without any rounding at all. 回答1: The solution is to use the normalize() method: {{ balance.bitcoins

Django: what does “load” do (in a template file)?

人盡茶涼 提交于 2019-12-08 14:31:57
问题 As "load" is far too generic for searching: What is the purpose of "load" and what does it do in this particular case? - in a template file, base_weblog.html, {% load weblog %}{% render_month_links %} Are some naming conventions used in order for "load" to do its job? E.g. names of folders and/or files and/or class names? Where is the documentation for "load" and can you elaborate? Details: The example is from the source for http://www.djangoproject.com/ - direct download URL is through http:

Traversing multi-dimensional dictionary in django

旧街凉风 提交于 2019-12-08 13:55:34
问题 I'm a PHP guy on my first day in Python-land, trying to convert a php site to python (learning experience), and I'm hurting for advice. I never thought it would be so hard to use multi-dimensional arrays or dictionaries as you pythoners call them. So I can create multi-dimensional arrays using this, but i can't loop it in a django template. this doesnt work but i imagine i cant loop through it if i could get it to work. {% for key,val in dictionary.items %} only works for actual dictionaries

Rendering another template from a button click in Django

∥☆過路亽.° 提交于 2019-12-08 13:31:06
问题 I have following template files in my django project: base.html base_test1.html base_test2.html Here both base_test1.html and base_test2.html extends base.html . My home page renders base_test1.html . In my home page, I have a button which when pressed should render base_test2.html . How should I achieve this? I have been trying to use jQuery ajax call so that when the button is pressed, I call the corresponding view in the views.py of my application. But that doesn't seem to be working since