django-templates

Django-compressor and template inheritance

穿精又带淫゛_ 提交于 2019-12-03 02:42:22
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 second isn't. In similar scenarios, I've confirmed that the issue is inheritance. I don't want to keep

Django: Switching to Jinja2?

巧了我就是萌 提交于 2019-12-03 02:32:56
问题 I've got a couple small (500 or 600 lines of template code) Django sites, and I'd like to migrate them to using Jinja2… But I'd like to get some idea of how much work it will be. So, in general, about how much work is it to migrate a small Django site to Jinja2? And is it “worth it”? 回答1: While it's just my own experience, I found converting from Django to Jinja2 to be worthwhile for the following reasons: The design and implementation of Jinja2 seemed more intuitive to me, both as a software

Django Newbie : “Reverse not found”

情到浓时终转凉″ 提交于 2019-12-03 02:26:20
I have a line in a Django form : {% for aa in my_array %} which seems to be triggering this error : Template error Caught an exception while rendering: Reverse for 'dev_env.profiles.views.viewPlan' with arguments '('',)' and keyword arguments '{}' not found. What does this error message really mean? I suspect that either the line is correct, but the error message is wrong. Or the error is real but this line is a red-herring. What on earth should I be looking for? Update : Paulo sorted this, below. In fact, I had a {% url viewPlan planId %} a couple of lines away (so the reported error line was

What is Django's TEMPLATE_DEBUG setting for?

邮差的信 提交于 2019-12-03 02:09:16
I have been trying to find information about this setting but there isn't much. Can someone explain me what is this setting about? Should I turn it off in production?... Just want to learn about it, maybe I'm missing something important in django. (I use django 1.6) This setting helps with debugging errors/exceptions raised while rendering the templates. If it is set to True and DEBUG is True , Django would show you usual "fancy" error page with a traceback, request details and other important information, and highlight at which line the error happened . If it is set to False and DEBUG is True

Django static page?

99封情书 提交于 2019-12-03 01:59:47
问题 I want to make a static page which will be shown to the user only if he/she clicks on a link provided in one of my models. I can do this by making a Python page alone and calling it, but I want it be called from Django. The user interface should be constructed using the Django API only. Any suggestions? 回答1: With the class-based views in newer Django versions, one can use this in urls.py: from django.views.generic import TemplateView url(r'^about', TemplateView.as_view(template_name='path/to

How to disable HTML encoding when using Context in django

给你一囗甜甜゛ 提交于 2019-12-03 01:56:57
In my django application I am using a template to construct email body, one of the parameters is url, note there are two parametes separated by ampersand in the url. t = loader.get_template("sometemplate") c = Context({ 'foo': 'bar', 'url': 'http://127.0.0.1/test?a=1&b=2', }) print t.render(c) After rendering it produces: http://127.0.0.1/test?a=1&amp;b=2 Note the ampersand is HTML encoded as "&". One way around the problem is to pass each parameter separately to my template and construct the url in the template, however I'd like to avoid doing that. Is there a way to disable HTML encoding of

Template does not exist

隐身守侯 提交于 2019-12-03 01:46:57
I am new to Django. I made a folder named templates in my project and "base.html" inside it, it works fine. But when I make new folder inside templates welcome and then "home.html" and I write some lines of code in my views.py file as from django.shortcuts import render_to_response def hello(request): return render_to_response('welcome/home.html') and settings.py includes # Django settings for Telecom project. DEBUG = True TEMPLATE_DEBUG = DEBUG import os #BASE_DIR = os.path.dirname(os.path.dirname(__file__)) PROJECT_DIR = os.path.dirname(__file__) ADMINS = ( # ('Your Name', 'your_email

Django Templates - Changing context for an 'include' template

瘦欲@ 提交于 2019-12-03 01:43:01
I have a template that includes several tables. I want to use a sub-template which renders these tables in the same way. I can get it to work for a single table, by setting the context in the view and passing that to the template. But how do you change the data for to render another table for different data? **'myview.py'** from django.shortcuts import render_to_response table_header = ("First Title", "Second Title") table_data = (("Line1","Data01","Data02"), ("Line2","Data03","Data03")) return render_to_response('mytemplate.html',locals()) **'mytemplate.html'** {% extends "base.html" %} {%

Calling block inside an if condition: django template

杀马特。学长 韩版系。学妹 提交于 2019-12-03 01:09:36
I have been trying to call a block inside an if condition in django template. I have a base template . I have many other templates that extend the base template. I have defined a block in base template: {% block test_block %}Test{% endblock %} I then want to override this block on a certain condition in the other templates. If the condition fails, the block shouldn't get overridden. This is something what I have written: {% if test_value %}{% block test_block %}Development{% endblock %}{% endif %} This actually (or may be virtually) ignores the if condition. What I finally did: {% block test

how to check DEBUG true/false in django template - exactly in layout.html [duplicate]

这一生的挚爱 提交于 2019-12-03 01:03:08
This question already has answers here : How to check the TEMPLATE_DEBUG flag in a django template? (6 answers) I would like distinguish a look of some toolbar in layout.html depending if DEBUG = True or not. I am aware of this answer using django.core.context_processors.debug but it forces me to use RequestContext instead of Request what I not really like, btw how can I use RequestContext for layout.html which extends base.html ? And generally is there some better way to that than mentioned one or the one using custom template tag ? I am currently on Django 1.7 andilabs In newer versions of