django-templates

Django: Select option in template

谁都会走 提交于 2019-12-18 11:47:41
问题 In my Django template, I am using the list of objects in a drop down menu. I am processing it based on the selection. The HTML Template: <select id="org" name="org_list" onChange="redirectUrl()"> <option value="" selected="selected">---SELECT---</option> {% for org in organisation %} <option value="{{org.id}}">{{org.name|capfirst}}</option> {% endfor %} </select> The problem is that when I am selecting the value from the drop down menu, I am getting the contents which belong to the selection.

django - what goes into the form action parameter when view requires a parameter?

前提是你 提交于 2019-12-18 11:02:31
问题 This is what I have: myview.py with a view that takes a parameter user : def myview(request, user): form = MyForm(request.POST) .... return render_to_response('template.html',locals(), context_instance=RequestContext(request)) The user gets passed through an url. urls.py : ... urlpatterns += patterns('myview.views', (r'^(?P<user>\w+)/', 'myview'), ) ... I also have a template.html with a form: <form name="form" method="post" action="."> ... </form> What goes in the the form action parameter

django - what goes into the form action parameter when view requires a parameter?

只谈情不闲聊 提交于 2019-12-18 11:02:23
问题 This is what I have: myview.py with a view that takes a parameter user : def myview(request, user): form = MyForm(request.POST) .... return render_to_response('template.html',locals(), context_instance=RequestContext(request)) The user gets passed through an url. urls.py : ... urlpatterns += patterns('myview.views', (r'^(?P<user>\w+)/', 'myview'), ) ... I also have a template.html with a form: <form name="form" method="post" action="."> ... </form> What goes in the the form action parameter

django templates: include and extends

偶尔善良 提交于 2019-12-18 10:03:15
问题 I would like to provide the same content inside 2 different base files. So I'm trying to do this: page1.html: {% extends "base1.html" %} {% include "commondata.html" %} page2.html: {% extends "base2.html" %} {% include "commondata.html" %} The problem is that I can't seem to use both extends and include. Is there some way to do that? And if not, how can I accomplish the above? commondata.html overrides a block that is specified in both base1.html and base2.html The purpose of this is to

Need to have a Required and Optional Fields in Django Formset

耗尽温柔 提交于 2019-12-18 09:39:50
问题 I created a formset that has maximum of 5 images to be attached; 1 - but I want the Validation to run only when the user has not attached any image (ValidationError('atleast 1 image is required')) , 2- This program is also not allowing the User to save when 1, or 2, or 3 images are attached, which I really need. So if there is 1 image or 2, that should be allowed to save. 3 - I also need to make the 1 radio-button to be selected by default, to make the selected image to be the one dispalyed

Django 1.5.5 displays original (en) strings always (does not translate)

那年仲夏 提交于 2019-12-18 09:29:26
问题 I'm trying to implement simple Django 1.5.5 string translation in templates. I have: USE_I18N = True in settings.py 'django.middleware.locale.LocaleMiddleware' in MIDDLEWARE_CLASSES in settings.py 'django.core.context_processors.i18n' in TEMPLATE_CONTEXT_PROCESSORS in settings.py Some {% trans "My string" %} strings in templates {% load i18n %} in all templates Ran python manage.py makemessages -l he Translated my strings using Poedit Ran python manage.py compilemessages LOCALE_PATHS = ('conf

How can i round a value in django template without using the filter

五迷三道 提交于 2019-12-18 07:36:13
问题 Is there any way that I can do some python math function in django template. Actually I need to round a variable value and I want to achieve this without using the filters. For example like {{math.round(total)}} . 回答1: You can use floatformat to round of the value in django template. {{ total|floatformat }} If you want to perform more mathematical operations, you can try django-mathfilters. Or you could write your custom template tag and perform the operations in that template tag. 来源: https:

How to pass javascript variable to django custom filter

空扰寡人 提交于 2019-12-18 04:25:17
问题 Is there a way to access a JavaScript variable in django template code as shown below: var tags_v1 = '{{ form.tags_1.value }}'; tags_v1 = tags_v1.split('{{ form.value_delim }}'); tags_v1 = tags_v1.map(function (item) { return '{{ $(item)|get_tag }}'; }) ; I want to pass the value of "item" as variable to the custom filter "get_tag". 回答1: There is an important distinction between Django template code and in-browser JavaScript that you seem to be missing: Django templates are built on the

Access STATIC_URL from within a custom inclusion template tag

不羁的心 提交于 2019-12-18 04:14:14
问题 I have created a custom inclusion template tag that accepts a single Update model object. Template tag: @register.inclusion_tag('update_line.html') def update_line(update): return {'update': update} update_line.html : <tr><td class="update">{{ update }}</td><td class="ack"> <img id="update-{{ update.pk }}" class="ack-img" src="{{ STATIC_URL }}img/acknowledge.png" alt="Acknowledge" /></td></tr> The problem is that {{ STATIC_URL }} is not available in my inclusion template tag template, even

Override existing Django Template Tags

人盡茶涼 提交于 2019-12-18 03:56:47
问题 Is it possible to override an existing Django Template Tag or is it necessary to customize the template file and create a new Template Tag? 回答1: Yes. As django is basically a python library (as with everything in python) you can over-write anything you'd like. It's not clear exactly what you'd like to do but it really is pretty easy to roll-your-own templatetag, the docs are pretty clear: https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-tags This is