django-templates

Django. How to display list of objects in one line using for loop in templates?

跟風遠走 提交于 2019-12-24 12:39:11
问题 I want to display list of objects in one line using django template tags, That piece of code: {% for object in my_objects %} <p> {{ object }} </p> {% endfor %} gives me that kind of result: obj1 obj2 obj3 . . . etc. Is there any way, to get that kind of result(with comas): obj1, obj2, obj3, ... etc. Thank You for anwsers. 回答1: Did you try ? <p> {% for object in my_objects %} {{ object }}{% if not forloop.last %},{% endif %} {% endfor %} </p> 回答2: Simpler solution than the one given by Totem:

Copy Selected Checkbox Value From One Checkbox To Another Immediately Using JQUERY

本秂侑毒 提交于 2019-12-24 12:12:56
问题 I'm relatively new to Jquery and have been struggling with this problem for the last day or so. I am trying to do something seemingly simple, but I can't quite work it out. I have two identical checkboxes with many entries and multiple choices can be selected by the end user in either checkbox. If a value in checkboxa is selected, I want it to immediately select the identical value in the checkboxb. I have researched many solutions, and I have tried the following: $(document).ready(function (

formset is valid but form has no attribute cleaned_data!

一笑奈何 提交于 2019-12-24 11:42:03
问题 Ok, so I have a formset that is valid. But gives me a error that that form has no attribute cleaned_data.. Honestly I have absolutely no clue what's happening.. I tried my code on terminal and it returned a empty dictionary.. without errors.. forms: class Clinical(forms.Form): _names = list(ClinicalForm.objects.values_list('form_id', 'form_name')) _names.append(("New", u'Nova entrada')) cliform_name = forms.ChoiceField(widget=RadioSelect(), choices=_names, label ="", required=True) views:

Django templates, including page(s) that injects code into parent block

牧云@^-^@ 提交于 2019-12-24 11:28:52
问题 Is it possible to include a template (with include django template tag) within another template and "inject" some content to the page that includes (parent) through block tag, or something similar? Let's say I have the following file structure within my project: App/ (...) templates/ base.html index.html _include1.html _include2.html _include3.html _include4.html Code for base.html : <!DOCTYPE html> <html> <head lang="en"> (...) </head> <body> <script type="application/javascript"> $(function

Totals/Subtotals in Django template

好久不见. 提交于 2019-12-24 11:26:51
问题 I'm having difficulty wrapping my head around a simple problem. How do you calculate totals and subtotals in a django template? Let's say I want to generate a report of customer's orders, something like: Desired Report Output Customer1 1 Widgets $ 2 1 Bobbins $ 1 Subtotal $ 3 Customer2 2 Widgets $ 4 2 Bobbins $ 2 Subtotal $ 6 TOTAL $ 9 Let's assume we populate a dictionary in our view orgs = {} orgs['Customer1'] = [ { 'qty': 1, 'descr' : 'Widgets', 'price': 2 }, { 'qty': 1, 'descr' : 'Bobbins

django-userena removing mugshot

依然范特西╮ 提交于 2019-12-24 11:00:04
问题 I am building a site which uses userena for the profile and registration part. The problem is that I am trying to remove the mugshot upload part and the profile privacy(registered,open,closed) from edit profile page so that userena uses gravatar only and the profiles are public for all. But in the template there is just <fieldset> <legend>{% trans "Edit Profile" %}</legend> {{ form.as_p }} </fieldset> <input type="submit" value="{% trans "Save changes" %}" /> </form> I am trying to find out

Combining two queryset into a template tag

浪子不回头ぞ 提交于 2019-12-24 10:08:39
问题 I have two models news.article and portfolio.entry. Both models have a BooleanField for setting "is_campaign" to true. Im trying to write a custom templatetag so I can get the latest campaign article (There should only be one) Here is my templatetag: campaign_article.py from itertools import chain from django import template from news.models import Article from portfolio.models import Entry register = template.Library() def get_campaign(): #Get the newest news article with is_campaign=True

Django cant find templates

╄→гoц情女王★ 提交于 2019-12-24 10:02:01
问题 So ive been trying to setup a django settings module that will check the environment variable and load settings. Heres what my settings module looks like /templates home.html /settings base.py prod.py dev.py test.py base.py PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) TEMPLATE_DIRS = [ os.path.join(PROJECT_ROOT, "templates"), ] urls.py from django.views.generic.simple import direct_to_template urlpatterns = patterns('', url(r"^$", direct_to_template, {'template' : 'home.html' },

How to output a graph from Matplotlib in Django templates?

ε祈祈猫儿з 提交于 2019-12-24 09:55:31
问题 Given this example taken from here: def simple(request): import random from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure from matplotlib.dates import DateFormatter fig=Figure() ax=fig.add_subplot(111) x=[] y=[] now=datetime.datetime.now() delta=datetime.timedelta(days=1) for i in range(10): x.append(now) now+=delta y.append(random.randint(0, 1000)) ax.plot_date(x, y, '-') ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d')) fig

Django TemplateDoesNotExist in production server when it works in development

删除回忆录丶 提交于 2019-12-24 09:08:12
问题 I get the following error. It's ONLY IN PRODUCTION where I deploy Django application using apache + mod_wsgi. IT WORKS PERFECTLY IN DEVELOPMENT server(my computer): TemplateDoesNotExist at / base.html postmortem. as you can see only one of my two folders from settings are being searched: Django tried loading these templates, in this order: Using loader django.template.loaders.filesystem.Loader: Using loader django.template.loaders.app_directories.Loader: /home/bot_frontend/horses/templates