django-templates

Django-easy-pdf, header on every page of the document

你说的曾经没有我的故事 提交于 2019-12-06 22:52:33
I am trying to export some data in a PDF file. I am using: Django 1.9.12 django-easy-pdf 0.1.0 Python 2.7 The export works fine and all (no problem with my view) but I am struggling with adding a page header into every page of the document. At this point I can only render it on the first page. I have no such problem with the footer, it renders properly on every page. My template is as follows: {% extends "easy_pdf/base.html" %} {% block extra_style %} <style type="text/css"> @page { size: landscape; margin-left: 1cm; margin-right: 1cm; margin-top: 1.5cm; margin-bottom: 2cm; @frame footer {

Django: How to display Validation errors not specific to a field?

烈酒焚心 提交于 2019-12-06 20:37:39
问题 I have errors raised in the form's clean method (not tied to a field). How do I display them in the template? I tried {{ forms.errors }} and {{ form.non_field_errors }} but neither worked. 回答1: According to the docs, they go in a special field ( __all__ ) and should be accessed via the non_field_errors() method. At a guess, I'd say that method returns a sequence. 来源: https://stackoverflow.com/questions/1883469/django-how-to-display-validation-errors-not-specific-to-a-field

Speeding up templates in GAE-Py by aggregating RPC calls

依然范特西╮ 提交于 2019-12-06 20:37:27
Here's my problem: class City(Model): name = StringProperty() class Author(Model): name = StringProperty() city = ReferenceProperty(City) class Post(Model): author = ReferenceProperty(Author) content = StringProperty() The code isn't important... its this django template: {% for post in posts %} <div>{{post.content}}</div> <div>by {{post.author.name}} from {{post.author.city.name}}</div> {% endfor %} Now lets say I get the first 100 posts using Post.all().fetch(limit=100) , and pass this list to the template - what happens? It makes 200 more datastore gets - 100 to get each author, 100 to get

Django - How to use custom template tag with 'if' and 'else' checks? [duplicate]

假如想象 提交于 2019-12-06 20:30:40
问题 This question already has answers here : if..else custom template tag (4 answers) Closed 3 years ago . I have made a custom template tag for permissions using python: register = template.Library() @register.simple_tag def get_user_perm(request, perm): try: obj = Profile.objects.get(user=request.user) obj_perms = obj.permission_tags.all() flag = False for p in obj_perms: if perm.lower() == p.codename.lower(): flag = True return flag return flag except Exception as e: return "" Then I loaded

Django Template Not Found

隐身守侯 提交于 2019-12-06 19:27:17
问题 I have a Django problem which only occasionally has problems finding Templates. It will be running fine for hours, and then suddenly not be able to serve certain templates. Occasionally the problem will correct itself, but can always be fixed by running touch <template> . My current solution is a cronjob which executes touch <project root> every minute, and that works so long as cron keeps up. However, I want to figure out a proper solution to my problem. Relevant Settings: PROJECT_ROOT = os

Django 1.7 - updating base_site.html not working

会有一股神秘感。 提交于 2019-12-06 18:36:36
问题 I'm following the tutorial for django 1.7 (again). I cannot get the admin site to update. I've followed this: Django: Overrideing base_site.html this: Custom base_site.html not working in Django and a couple of offsite things links. My settings file looks like this: """ Django settings for website project. For more information on this file, see https://docs.djangoproject.com/en/1.7/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.7/ref

Django template variable value to string literal comparison fails

╄→尐↘猪︶ㄣ 提交于 2019-12-06 18:21:56
问题 I have the following code in my template that supposed to compare the value of watchinstance.shift , which can be either "DAY" or "NIGHT", to a literal string "DAY". The comparisson always fails. {% for watchinstance in watchinstance_list %} {% if watchinstance.shift == "DAY" %} <p>shift is DAY</p> {% endif %} {% endfor %} Using ifequal doesn't work either: {% for watchinstance in watchinstance_list %} {% ifequal watchinstance.shift "DAY" %} <p>shift is DAY</p> {% endifequal %} {% endfor %}

Displaying a timedelta object in a django template

故事扮演 提交于 2019-12-06 17:16:26
问题 I'm having trouble getting my django template to display a timedelta object consistently. I tried using the time filter in my template, but nothing is displayed when I do this. The timedelta object is shown as follows on the errors page if I use Assert False: time datetime.timedelta(0, 38, 132827) This displays the time difference as: 0:00:38.132827 I would like to only show the hours, minutes, and seconds for each timedelta object. Does anyone have any suggestions on how I can do this? 回答1:

Is it possible to use django's custom template tags to insert code in other blocks in the template?

与世无争的帅哥 提交于 2019-12-06 15:57:52
I'm writing a custom template tag that wraps an HTML element with some code to make it editable. This is backed up by some CSS, and JS that takes care of sending the data to the server to save it. This component requires the inclusion of <script type="text/javascript" src="../myscript.js"></script> at the bottom of the page and <link rel="stylesheet" type="text/css" href="../mystyle.css"> at the top. I already have two "js" and "css" template blocks in the page template. My question - is there a way for for the custom template tag to include these scripts once in the relevant page blocks, if

Django - Rating Model Example DetailView Template

独自空忆成欢 提交于 2019-12-06 15:24:34
问题 Here is the context: I have users, videos, topics, criterias and ratings A video has a topic A topic has criterias A user can create a video for a given topic A user can rate a video on the criterias given for the concerned topic. Here is my model for that purpose: RATE_CHOICES = zip( range(1,5), range(1,5) ) class VideoCrit(models.Model): """Criteria to rate videos on. Can be multiple for each Topic of Video""" name = models.CharField(max_length=50) def __unicode__(self): return self.name