django-templates

Django: 404.html exists but 500.html is used

蹲街弑〆低调 提交于 2019-12-13 06:25:39
问题 http://127.0.0.1:8000/app/slug/ With Debug=True I get Page not found (404) - No entry found matching the query . With Debug=False I get shown the projectName/templates/500.html instead of 404.html . Both look exactly the same. 500.html : {% extends "base.html" %} {% block title %}server error{% endblock %} {% block content %} <h3>Error 500: server error</h3> {% endblock %} 404.html : {% extends "base.html" %} {% block title %}page not found{% endblock %} {% block content %} <h3>Error 404:

Django template tags in JavaScript - invalid syntax without quotes, invalid syntax with quotes

本秂侑毒 提交于 2019-12-13 06:20:57
问题 It is possible you have Javascript read vars from Django template tags like var spec = "{{ foo }}"; . However, if foo needs to be a JSON object. it becomes like this: var spec = "{"2": {"guid": 2, "contentBlocks": {"2_1": {"guid": "2_1", "type": "list"}}}}"; The preceding and closing quotes make this an invalid JavaScript syntax, however, if I leave them out, it is also an invalid syntax var spec = {{ foo }}; What would be the best way to solve this problem? Either to have foo output the

How to prevent static files being included multiple times in Django templates?

◇◆丶佛笑我妖孽 提交于 2019-12-13 06:17:18
问题 I have some template tags, which include some JavaScript and CSS files in the header. The problem is, that if I use these tags multiple times in the same template, the files are included multiple times unnecessarily. Is there a conventional way to prevent this from happening. (Like #ifdef in C++) 回答1: I think you need to organise your templates so that includes are made in the top hierarchy one, and only inherits from it in only the templates where you need it. Django provides a very powerful

Why is Django blocktrans working one place and not another?

女生的网名这么多〃 提交于 2019-12-13 06:14:16
问题 I have two Django templates (in a Pinax 0.9.x project) with text in a blocktrans block. One is working and the other isn't. The one that's working looks like: {% extends "site_base.html" %} ... {% block body %} <h1>ABC</h1> <h2><em>DEF</em></h2> <p> {% blocktrans %} GHI ... The one that's not working is getting a debug mode error of: TemplateSyntaxError at /JKL/ Invalid block tag: 'blocktrans', expected 'endblock' or 'endblock body' It follows those headings by giving the following source

How to load app specific template tag in Django?

本小妞迷上赌 提交于 2019-12-13 06:03:50
问题 I'm calling this template tag from a different app within the same project. However I'd like to make changes on it to make it work better on the app I'm working on. I simply created a templatetags directory inside my app and copied the template tag file inside then went about my changes. So it kinda looks like this: theotherapp/templatetags/sometags.py myapp/templatetags/sometags.py What I noticed is that the other app's template tag is still the one being used. But when I change the filename

Loading images in a static file

隐身守侯 提交于 2019-12-13 05:51:04
问题 So I have completed the Django tutorial, play around with it some, and feel that I have a good understanding of Django. The only problem I am facing is that when I try to display a static page for a landing page, I cannot seem to get any images to load. First off I have tried two different methods of displaying a static landing page. First: # main app urls.py from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('',

Django Forms: How to iterate over a Choices of a field in Django form

大城市里の小女人 提交于 2019-12-13 05:19:24
问题 I dont know if I am doing this in the right manner. I have a form: class ConnectSelectMultipleForm(forms.Form): class Meta: model = Connect def __init__(self, *args, **kwargs): messages = kwargs.pop('messages') choices = [] if messages: pass else: messages = [] for message in messages: index = (message.id, {message.sender, message, message.id}) choices.append(index) super(ConnectSelectMultipleForm, self).__init__(*args, **kwargs) self.fields['message'] = forms.MultipleChoiceField(choices

Passing variable to a form for display in django

拟墨画扇 提交于 2019-12-13 05:04:58
问题 views.py def when(request): user = request.user report = Report.objects.get(user=request.user) reportform = ReportForm(instance=report) settings = Settings.objects.get(user=request.user) settingsForm = SettingsForm(instance=settings) # settings=Settings.objects.get(user=2) if settings.date_format == '0': date = report.manual_date.strftime('%d/%m/%Y') else: date = report.manual_date.strftime('%m/%d/%Y') if settings.time_format == '0': time = report.manual_time.strftime('%I:%M%p') else: time =

Using image in a template django

Deadly 提交于 2019-12-13 04:57:04
问题 I want to view images, in a template, but I don't understand what I'm doing wrong. models.py class Item(models.Model): name = models.CharField(verbose_name = "Название", max_length = 100) TYPE_ITEMS = ( ("shirt", "Футболка"), ("shoes", "Обувь"), ("bags", "Рюкзаки и сумки"), ("heads", "Головные уборы"), ("others", "Другое"), ) type_item = models.CharField(verbose_name = "Тип продукта", choices = TYPE_ITEMS, max_length = 6, default = "shirt") other = models.CharField("другая информация", max

Django: How to add dynamic classes to select options in a form

邮差的信 提交于 2019-12-13 04:52:40
问题 I have a ModelForm that I'm rendering in the template with django-widget-tweaks. I have a ChoiceField select that prints out something like this: <select> <option value="object.id">object.name</option> </select> But for Javascript manipulation purposes, I need the following: <select> <option value="object.id" class="object.otherPropery">object.name</option> </select> django-widget-tweaks has an add_class function, but it only adds a class to the select box, not the contained options. I have