django-templates

Checking if something exists in items of list variable in Django template

天大地大妈咪最大 提交于 2020-01-01 10:50:18
问题 I have a list of sections that I pass to a Django template. The sections have different types. I want to say "if there is a section of this type, display this line" in my template, but having an issue. What I'm basically trying to do is this. {% if s.name == "Social" for s in sections %} Hello Social! {% endif %} But of course that's not working. Any idea how to basically in one line loop through the items in a list and do an if statement? ADDITIONAL INFO: I could potentially have multiple

render_to_response gives TemplateDoesNotExist

笑着哭i 提交于 2020-01-01 09:24:07
问题 I am obtaining the path of template using paymenthtml = os.path.join(os.path.dirname(__file__), 'template\\payment.html') and calling it in another application where paymenthtml gets copied to payment_template return render_to_response(self.payment_template, self.context, RequestContext(self.request)) But I get error TemplateDoesNotExist at /test-payment-url/ E:\testapp\template\payment.html Why is the error coming? Edit : I have made following change in settings.py and it is able to find the

{% trans “string” %} not working on templates but {% trans variable %} does

岁酱吖の 提交于 2020-01-01 09:14:11
问题 I'm quite new to Django and I'm working on a project with i18n, the thing is that I have translated some variables using .manage.py makemessages / compilemessages on my template file, but when I use {% trans "my string" %} I got the same "my string" for all the languages. What am I doing wrong? Here's the code for the views.py and the idioma.html views.py: #some code here... def idioma(request): output = _("Mensaje en espanol") return render_to_response( 'idioma/idioma.html', { 'idioma' :

TypeError: unsupported operand type(s) for -: 'datetime.time' and 'datetime.time'

落花浮王杯 提交于 2020-01-01 08:20:36
问题 my models.py: class Attendancename(models.Model): teacher_name = models.ForeignKey(Teachername, default='Ram') date = models.DateField('Date', default=datetime.datetime.today) intime = models.TimeField('IN-TIME', auto_now=True) outtime = models.TimeField('OUT-TIME', auto_now=True) def hours_conversion(self): startdelta = datetime.timedelta(hours=self.intime.hours, minutes=self.intime.minutes, seconds=self.intime.seconds) enddelta = datetime.timedelta(hours=self.outtime.hours, minutes=self

Django CMS Page Title Doesn't Render

大城市里の小女人 提交于 2020-01-01 05:00:06
问题 I'm currently working on a project that uses django-registration and Django CMS. When display the pages that implement django-registration my page titles do not render. Currently have <title>{% page_attribute page_title %}</title> in base.html which all my templates inherit from. In the pages that do not use django-registration the titles display just fine, but django-registration display as <title></title> My pages are all created within the CMS and everything else is rendering correctly. If

Django: Built-in include tag vs custom inclusion tag

时光毁灭记忆、已成空白 提交于 2020-01-01 04:31:28
问题 What is the difference between Django's built-in include tag and custom inclusion tags? I have read the documentation, and both seem to to achieve the same goal: render a template passing it a context or variable. 回答1: They serve different purposes. The include tag simply includes the content from an existing template in its entirety and unmodified. A custom inclusion tag passes the context to a function which can contain logic to manipulate the context before passing it to a template. For

django template if or statement

谁说胖子不能爱 提交于 2020-01-01 03:52:05
问题 Basically to make this quick and simple, I'm looking to run an XOR conditional in django template. Before you ask why don't I just do it in the code, this isn't an option. Basically I need to check if a user is in one of two many-to-many objects. req.accepted.all and req.declined.all Now they can only be in one or the other (hence the XOR conditional). From the looking around on the docs the only thing I can figure out is the following {% if user.username in req.accepted.all or req.declined

Django and models with multiple foreign keys

可紊 提交于 2020-01-01 02:44:15
问题 I am new to Django and I've been impressed so far by its capabilities. I am playing with more complex models and I am have problem to use them properly. Using Django 1.3, I am trying to write a summary page which would present the three models below with the following structure. In other words, a list of trips with their destinations and activities. Trip 1 Destination 1 Destination 2 Activity 1 Trip 2 Destination 1 Activity 2 Models Trip <-> TripDestination <-> Destination (a trip can have

Django: How to access the display value of a ChoiceField in template given the actual value and the choices?

醉酒当歌 提交于 2020-01-01 02:00:09
问题 I have a ChoiceField in a bound form, whose choices are: [('all', 'All users'), ('group', 'Selected groups'), ('none', 'None')] In the template, I have no problem accessing its bound value (the actual value to be stored; the first element of each tuple) and the choices. With these pieces of info in hands, I know I should be able to access the display values, or the second element of each tuple. But how can I do that in the template? Thanks. 回答1: I doubt that it can be done without custom

Django-compressor and template inheritance

旧城冷巷雨未停 提交于 2019-12-31 22:38:53
问题 I'm using the django-compressor app in Django 1.2.3 to minify and merge a number of included CSS and JS files. In a base template, I have {% load compress %} {% compress js %} {% block js %} <script type="text/javascript" src="/site_media/js/jquery.query-2.1.7.js"> {% endblock %} and in a child, {% block js %} {{block.super}} <script type="text/javascript" src="/site_media/js/jquery.validate.min.js"> {% endblock %} When the templates render, the first script tag is correctly minified, but the