django-templates

include bootstrap modal template with template tags

烂漫一生 提交于 2019-12-08 01:14:10
问题 I'm trying to create a bootstrap modal that can be included in my html files since I'm putting forms in modal and I don't want to create a new mdoal everytime. It works fine, except for trying to include the form. Which is of course the important part. How could I include a template context variable inside a template tag? modal_base {% load crispy_forms_tags %} <div id="{{ modal_form_id }}" class="modal fade" ariahidden="True"> <div class="modal-dialog"> <div class="modal-content"> <div class

Using ifequal in Django

安稳与你 提交于 2019-12-08 00:48:04
问题 I'm sure there is something silly I'm missing here, but I'm trying to use ifequal to evaluate a template variable. Here's my model: USER_TYPES = ( ('instructor', 'Instructor'), ('student', 'Student'), ) class UserProfile(models.Model): type = models.CharField( choices=USER_TYPES, max_length=12 ) user = models.ForeignKey( User, unique=True ) def __unicode__(self): return u'%s' % (self.type) ...and I'm using this in the template: {% ifequal user.userprofile_set.get student %} You're a student!

Django no module named utils

风流意气都作罢 提交于 2019-12-08 00:44:29
问题 I know this question has been asked before but after looking into it I can't help but feel I missed something. So I previously had a problem getting django-compressor installed but after a bit of struggling i managed to get it installed. When I run my django application though it stops on execute_from_command_line(sys.argv) in my manage.py and throws this error: Traceback (most recent call last): File "C:\Users\PCDOM\Desktop\Power\pm_app\manage.py", line 17, in <module> execute_from_command

Django Template Arithmetic

一笑奈何 提交于 2019-12-07 22:59:53
问题 In my template, I am looping through a list, trying to make a two-column layout. Because of the desired two-column layout, the markup I need to write in the for loop is dependent on whether forloop.counter0 is even or odd. If I had the full power of Python in the template language, determining the parity of forloop.counter0 would be trivial, but unfortunately that is not the case. How can I test whether forloop.counter0 is even or odd using the Django template language, or just as good, is

Django - Admin - How to override change_list template for Model Proxy?

蹲街弑〆低调 提交于 2019-12-07 19:42:56
问题 I made a simple Django app. I have one model "Visitor". My goal is to have two tables appear in the Django admin. One with all of the visitors and one with only those for today. I got everything working with the code below by following these instructions. But I'm not sure how to override just the change_list.html for just VisitorExpectedTodayProxy. I tried following the instructions here and I created Site/templates/admin/VisitorLog/VisitorExpectedTodayProxy/change_list.html and made my

Does Django's render_to_response cache unrendered templates or load from disk every time?

久未见 提交于 2019-12-07 18:39:01
问题 Fetching a template from disk is significantly slower than pulling it out of something like memcached, so loading them from disk each time is wasteful. Does Django cache unrendered templates in memory or in the CACHE_BACKEND or do I have to implement that myself? 回答1: Django comes with a cached template loader as well. 回答2: I can't seem to find anyplace where the filesystem loader might cache the templates. It sure does look like it loads them every time. This probably isn't really a problem,

Why does django not use my SHORT_DATE_FORMAT with date template tag?

让人想犯罪 __ 提交于 2019-12-07 18:35:23
问题 I have troubles understanding why django doesn't use my SHORT_DATE_FORMAT in templates when I specify it for the date template tag. My settings are: TIME_ZONE = 'Australia/Melbourne' SHORT_DATE_FORMAT = 'd/m/Y' LANGUAGE_CODE = 'en-AU' USE_I18N = True USE_L10N = True USE_TZ = True In my template: {{ asset.upload_date|date:"SHORT_DATE_FORMAT" }} I would expect '21/01/2014' but I get '01/21/2014'. 回答1: It's actually due to USE_L10N=True + Django still not having a locale conf for Australia ( en

django sort the query elements in a weekly monthly daily fashion

混江龙づ霸主 提交于 2019-12-07 18:18:16
问题 I am getting a list of people and the tests they have taken from an api in the same project. I would like the user to have an option to see the number of tests that have taken place in a city with three options - daily/weekly/monthly. models.py class City(models.Model): city_name=models.CharField(max_length=100,default='',blank=False) class Person(models.Model): title = models.CharField(max_length=3,default="mr",blank=False) name = models.CharField(max_length=50,default='',blank=False)

Django could not load template tag

最后都变了- 提交于 2019-12-07 17:54:11
问题 I have created a templatetags folder inside my application and inside a file named posts.py , I have written the following code; from django.template import Library, Node from advancedviews.models import Post register = Library() class AllPost(Node): def render(self,context): context['all_posts'] = Post.objects.all() return '' def get_all_posts(parser,token): return AllPost() get_all_posts = register.tag(get_all_posts) Now, I try to load this template tag inside my template; {% load get_all

how to get checkbox value in django?

烂漫一生 提交于 2019-12-07 17:31:58
问题 <tr name="item"> <td><input type="checkbox" ></td> <td>>{{ foo }}</td> <td> {{ bar }} </td> </tr> Now I want that in django views request.POST.getlist('item') returns the value of ie foo and bar . But it is returning null. 回答1: I'm not sure to understand everything you asked, but if you want to get "foo" and "bar" when the user submit the form, you will have to add them in a form element like hidden or textfields (depending on if the user can modify them or not). The server will never receive