django-templates

Why doesn't Django produce locale files from template files in another directory?

China☆狼群 提交于 2019-12-23 10:27:34
问题 Version info: Django version 1.3 pre-alpha SVN-13858 Ubuntu GNU/Linux 10.10 I'm totally new to i18n and l10n in Django and currently I'm trying to make my Django project available in Dutch (in addition to its default language: English). I tried to apply the instructions given at http://docs.djangoproject.com/en/dev/topics/i18n/translation/ and http://www.djangobook.com/en/2.0/chapter19/ but I had no success. I don't know if this is related to my directory structure and template files being in

Storing and escaping Django tags and filters in Django models

风流意气都作罢 提交于 2019-12-23 10:26:07
问题 I am outputting content from my models to my templates, however some model fields call data stored in other models. This happens only in a few fields. I am wondering whether using an if tag to evaluate this would be more efficient compared to storing the django tags inside the models. Answers to this question say that storing django tags in models is a bad idea without giving reasons (although I think one of the reasons may be someone else may inject some tags in the Database). Assuming that

Can custom Django filters access request.user?

爱⌒轻易说出口 提交于 2019-12-23 07:44:25
问题 Is it possible to access the current User (i.e. user in the template context) from a custom template filter? Obviously I can pass the user in as an argument, but if it's possible to just grab the current user, that would be more convenient. 回答1: Django filters aren't given any special access to the context from which they are called, they're just plain old functions. You'll need to pass in anything you want to use within the function. https://docs.djangoproject.com/en/dev/howto/custom

Best Practice for Context Processors vs. Template Tags?

我是研究僧i 提交于 2019-12-23 07:20:16
问题 In which cases is it better to create template tags (and load them into the template), than creating a context processor (which fills the request automatically)? e.g. I have a dynamic menu that has to be included into all templates, so I'm putting it into my base.html. What is the preferred usage: context processor or custom template tag? And why ? 回答1: Context processors is for putting data (information, content, objects) into the context used to render page. Template tags are for formatting

Nested blocks in Django templates

时光怂恿深爱的人放手 提交于 2019-12-23 06:48:10
问题 The master template in my Django app looks like this: {% block parent %} Some text... {% block child %} Default content here... {% endblock child %} ...some more text {% endblock parent %} Now, this template should be overwritten in a way that the child block is changed: {% extends "master.html" %} {% block child %} New content here... {% endblock child%} However, the rendering stays the same (printing "default content here..."). Have I missed something obvious or are nested blocks not

Newbie Django urls, views, and templates - how can this incredibly simple django project possibly be failing?

我是研究僧i 提交于 2019-12-23 05:32:09
问题 When the user lands at http://127.0.0.1:8000/ I would like to display an html page that says "welcome." When the user goes http://127.0.0.1:8000/time/ I would like to display the current time. I have followed instructions to the t and dotted every i. My settings are below. Why do I continue to get a TemplateDoesNotExist error? views.py from django.template.loader import get_template from django.shortcuts import render import datetime def current_datetime(request): now = datetime.datetime.now(

Django custom template tags in javascript

梦想与她 提交于 2019-12-23 05:21:07
问题 I have a custom template tag that returns suppose name of a student and roll number if passed as an argument id of the student. @register.inclusion_tag('snippet/student_name.html') def st_name_tag(profile, disp_roll=True, disp_name=True): #some calculations return {'full_name':student.name, 'roll':student.roll_number, } The template(included) consists of some Html file which is written in a single line(to avoid unterminated string literal error from js). I simply want to call the st_name_tag

Django template skip line every two iteration

一曲冷凌霜 提交于 2019-12-23 04:54:34
问题 I have the following html structure: <div class="row> <div class="box"></div> <div class="box"></div> </div> I am using pagination feature on Django to pass on 6 items per page. How would I go about iterating over the paginator generated object list while wrapper each two box divs with row div? 回答1: You can use the forloop.counter in the template {% for obj in obj_list %} {% if forloop.counter0|divisibleby:2 %} <div class="row"> {% endif %} <div class="box"></div> <div class="box"></div> {%

django checkbox select all by jquery

风格不统一 提交于 2019-12-23 04:51:46
问题 I want to select all checkbox when i click the top check, below is my code: run.html <script language="JavaScript" src="media/js/jquery-1.4.2.min.js"></script> <script language="javascript"> $("#selectAll").change(function() { $(".xxx:checkbox").attr('checked', this.checked); }); </script> Select All: <input type="checkbox" id="selectAll"><br /> <br /> One: <input type="checkbox" class="xxx" /><br /> Two: <input type="checkbox" class="xxx" /><br /> Three: <input type="checkbox" class="xxx" />

Django pagination with bootstrap

大城市里の小女人 提交于 2019-12-23 04:34:09
问题 I am about to add a pagination to my list of contacts. I am sitting over it the whole day and have no idea what I mixed up. Important thing is that I do have a working filters - so I can narrow the list. But from my understanding pagination should work anyway. In my case I see nothing so my guess is first "if" fails. If you could point me in the right direction. Best regards. Views.py def ContactsList(request): contacts_list = Contact.objects.all() Contacts_filter = LFilter(request.GET,