django-templates

Django - use custom template loader on a per-request basis?

*爱你&永不变心* 提交于 2019-12-24 03:19:07
问题 Is there a lower-level way to provide the list of loaders when rendering a template, as opposed to always having Django use the setting? I'd like to use a custom template loader instance for only a few views (I have my reasons). 回答1: It looks like you'll have to write some code of your own to do it. Let's take a look at the normal code path for loading templates, if you use, say, render_to_response , where the relevant part of the source is: return HttpResponse(loader.render_to_string(*args,

Django static files not loading with default setup

情到浓时终转凉″ 提交于 2019-12-24 03:16:24
问题 So I installed Bitnami Django stack, and enabled the admin module, and followed the tutorial for creating an admin menu for "Polls". However, when I go to /admin/ everything is white plaintext. All the css and images are 404 error. All I did was: enable in settings.py installed_apps: 'django.contrib.admin', In urls.py UNcommented: from django.contrib import admin admin.autodiscover() url(r'^admin/', include(admin.site.urls)), uncommented. In settings.py, I tried using default settings and

update value of a variable inside a template - django

为君一笑 提交于 2019-12-24 02:33:14
问题 I have seen enough number of examples that allow me to declare a new variable inside a template and set its value. But what I want to do is to update the value of a particular variable inside the template. For example I have a datetime field for an object and I want to add timezone according to the request.user from the template. So I will create a template filter like {% add_timezone object.created %} and what it will do is that it will add timezone to object.created and after that whenever

add float number in template (django)

倾然丶 夕夏残阳落幕 提交于 2019-12-24 01:53:23
问题 Maybe i'm missing something but i'm looking to add a float number, something like this: {%floatnumber|add:3.4%} Filter add round my result so I don't want to write my filter, but if is the only way, i'll copy add filter Now i'm doing this: def addf(value, arg): """Adds the arg to the value.""" return float(value) + float(arg) addf.is_safe = False register.filter(addf) 回答1: Right now it turns it into int. There is an open ticket and I even sent a patch, but it haven't been commited yet ;-)

extends not working in Django 1.9

我的未来我决定 提交于 2019-12-24 01:25:25
问题 When I add {% extends "X.html" %} to my child templates (the parent being "base.html"), only the parent template is loaded. When I take it away, the child template is loaded. I have another app where I have a seemingly identical inheritance structure, so I'm stumped. Here is "base.html": <!DOCTYPE html> {% load staticfiles %} <html> <head> {% block js %} <script src="{{ STATIC_URL }}js/jquery.1.12.4.min.js"></script> <script src="{{ STATIC_URL }}js/p5.js" {% endblock %} <title>myapp</title> <

template url reversal escaping surt arguments

你说的曾经没有我的故事 提交于 2019-12-24 01:08:15
问题 I'm having an issue where the template url reversal is escaping colon and parenthetical characters. I want these characters to remain unescaped in the anchor tag's href attribute. It used to behave this way when I was in django 1.3, but upgrading to 1.6, I notice that this does not behave as I want. What I have: surt = 'http://(gov/' browse_domain = 'gov' ... in template ... <a href="{% url 'nomination.views.url_surt' project.project_slug surt %}">{{ browse_domain }}</a> This yields: <a href=

Official advice for printing all Django form errors in a template not working…or not understood

为君一笑 提交于 2019-12-24 00:47:44
问题 I can't figure out how to print all form error messages in a Django (1.7) template, despite following the advice in the official docs and elsewhere. I have an account user/pass admin/admin. I've intentionally changed the minimum allowable username length in the LoginForm to 6, in an effort to get a "bad length" error, instead of a "bad user/pass combo" error (full form/view code at the bottom). According to the official docs, the following should print all error messages: {% if form.errors %}

Comparison of js andtemplate tags

∥☆過路亽.° 提交于 2019-12-23 22:42:20
问题 <script> function compare(profile_id) { {% ifequal '{{profile.id}}' %} selected_sub='selected'; {% endifequal %} } </script> How to compare {{profile.id}} and javascript variable profile_id 回答1: function compare(profile_id){ if (profile_id == {{ profilegroup.subject.id }}) \\ do something } Keep in mind, that the script must be in a template, not in some served statically file with scripts (it must be filled with values, to work). Remember also, that you simply have templated script, that

How to manually create a select field from a ModelForm in Django?

泄露秘密 提交于 2019-12-23 22:23:05
问题 I have a ModelForm where one of the field (named creator ) is a ForeignKey , so for {{ form.creator }} Django renders the <select> tag like this: <select id="id_approver" name="approver"> <option selected="selected" value="">---------</option> <option value="1">hobbes3</option> <option value="2">tareqmd</option> <option value="3">bob</option> <option value="4">sam</option> <option value="5">jane</option> </select> But I want to add a onchange event attribute so I can use AJAX later to do

Django Passing list of objects to template

巧了我就是萌 提交于 2019-12-23 21:13:09
问题 I have trouble of passing my get_profiles in the same template as r'^compose/$' here. r'^users/$' is what I'm using as a model and it works. "compose" is a function in my views.py. from django.conf.urls.defaults import * from django.views.generic.simple import redirect_to from django.views.generic.simple import direct_to_template from messages.views import * from userprofile.views import get_profiles urlpatterns = patterns('', url(r'^$', redirect_to, {'url': 'inbox/'}), url(r'^inbox/$', inbox