django-templates

Python datastructures into js datastructures using Django templates (lists and dicts)

风格不统一 提交于 2019-12-07 10:27:33
问题 I have a Django view that returns a list of dicts like so data = [{'year': 2006, 'books': 54}, {'year': 2007, 'books': 43}, {'year': 2008, 'books': 41}, {'year': 2009, 'books': 44}, {'year': 2010, 'books': 35}] c = { 'data': data, } return render(request, 'template.html', c) The template file has some basic JavaScript in it that does something like this. var data = "{{data}}"; console.log(data); //..... Then other functions The issue is that the data is coming into the JavaScript via the

Django template tag to insert or replace URL parameter

随声附和 提交于 2019-12-07 07:51:23
问题 Is anyone aware of a Django template tag that takes the current path and query string and inserts or replaces a query string value? e.g. given a request to /some/custom/path?q=how+now+brown+cow&page=3&filter=person The call {% urlparam 'page' 4 %} would generate /some/custom/path?q=how+now+brown+cow&page=4&filter=person . This wouldn't be too difficult to write from scratch, but as this seems like a very common task, I would expect a tag like this to be built-in. However, after reading

Django: No module named context_processors, Base URL

旧城冷巷雨未停 提交于 2019-12-07 07:33:50
问题 I've scoured the web for a solution but nothing seems to work. I'm getting the error: ImproperlyConfigured at /tool/page4/ Error importing module mysite.context_processors: "No module named context_processors" settings.py TEMPLATE_CONTEXT_PROCESSORS = ( # default context processors for Django 1.4 "django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors

Link stylesheets to Django template

℡╲_俬逩灬. 提交于 2019-12-07 07:28:49
问题 I have been looking at this tutorial and now have a stylesheet in /static/styles/ . The problem is that the template doesn't pick this up: <html> <head> <link rel="stylesheet" type="text/css" href="static/css/stylesheet.css" /> <title>Search</title> </head> <body> ... Do I need something in my settings file? Where am I going wrong? My project structure is: project - manage.py - project - static - templates - __init__ - etc.. EDIT My urls.py now looks like this: from django.conf.urls import

__init__() got an unexpected keyword argument 'attrs'

风流意气都作罢 提交于 2019-12-07 07:25:25
问题 forms.py class ImportExcelForm(Form): file = forms.FileField(attrs={'class':'rounded_list',}) I am trying to add css class to my filefield in forms.I am getting this error "__init__() got an unexpected keyword argument 'attrs'" What i did wrong. Thanks 回答1: attrs is not an argument to the field, it's an argument to the widget. file = forms.FieldField(widget=forms.FileInput(attrs={'class': 'rounded_list'})) Note that some browsers don't allow styling of the file input. 来源: https:/

Can not use unicode string in django template

筅森魡賤 提交于 2019-12-07 07:16:22
问题 I used "BỘ MÔN TOÁN" string in django template it raised error "'utf8' codec can't decode byte 0xd4 in position 569: invalid continuation byte" . But when I use "BO MON TOAN" string, it does'nt raise error. So, I used vietnamese in template and this is my code: {% extends "site_base.html" %} {% load i18n %} {% load staticfiles %} {% load url from future %} {% block body_base %} <div class="subject-box-title"> BỘ MÔN TOÁN </div> {% endblock %} And this is error in my project: What's happening

django forms error_class

拥有回忆 提交于 2019-12-07 07:03:18
问题 Is there a way to give a form a special error rendering function in the form definition? In the docs under customizing-the-error-list-format it shows how you can give a form a special error rendering function, but it seems like you have to declare it when you instantiate the form, not when you define it. So you can define some ErrorList class like: from django.forms.util import ErrorList class DivErrorList(ErrorList): def __unicode__(self): return self.as_divs() def as_divs(self): if not self

jinja2: How to make it fail Silently like djangotemplate

一个人想着一个人 提交于 2019-12-07 06:33:39
问题 Well i don't find the answer I'm sure that it's very simple, but i just don't find out how to make it work like Django when it doesn't find a variable i tried to use Undefined and create my own undefined but it give me problems of attribute error etc. def silently(*args, **kwargs): return u'' class UndefinedSilently(Undefined): __unicode__ = silently __str__ = silently __call__ = silently __getattr__ = silently but when i try this here it fails TypeError: 'unicode' object is not callable : {

How to use inbulit django templatetags in google-app-engine

*爱你&永不变心* 提交于 2019-12-07 06:22:35
问题 I am trying to use Django in built templatetags like markup and humanize in my google app , but its not working. I added markup and humanize in the INSTALLED_APPS. Still not working. How to use that? 回答1: Here is how to do it for humanize, others should be similar. At the end of the controller that invokes your template there is a function that looks like: def main(): run_wsgi_app(application) Add the following two lines just after def main(): from google.appengine.ext.webapp import template

Django custom 500 error template not displaying request.user

流过昼夜 提交于 2019-12-07 06:07:17
问题 I'm implementing custom 404 and 500 templates, but while the 404.html template seems to return request.user.is_authenticated fine, the 500.html template fails to return anything. I also checked for request.user and it's just blank on the 500 page. This is very strange, because when I trigger the 500 error, I receive the expected error report e-mail, and it clearly has USER properly defined in the request breakdown. Here's the code I'm using in views.py: def handler404(request): response =