django-templates

How to display the site's user friendly name in a template in Django?

孤人 提交于 2019-12-10 19:24:54
问题 I am searching for a way to display my Django-CMS site name in a template. I created a basic Django-CMS site following this guide. The default site is named Example.com and I was able to change this name, from within the admin section, to "My Super Site". Following what, I tried to customize and apply a theme to it, following this guide. It suggests to use {{ request.site.name }} to display the name of the site on a page. However this turns up empty and so does {{ request.site }} . I searched

{% extends “base.html” %} and {% block content %} inside if statement (Django app)

故事扮演 提交于 2019-12-10 18:53:03
问题 In a Django template, I want to show different things to authenticated and unauthenticated users. Specifically, something like the following: {% if not user.is_authenticated %} <div class="margin"> {{ group.topic }} </div> {% else %} {% extends "base.html" %} {% load humanize %} {% block content %} <div class="margin"> {{ group.topic }} <br> <b>members:</b> {% for member in members %} <a href="{% url 'profile' slug=member.username %}">{{ member.username }}</a>,  {% endfor %} <hr size=1> <form

.items not working on defaultdict in Django template

我怕爱的太早我们不能终老 提交于 2019-12-10 18:44:29
问题 I can't get .items to work in my Django template: copy and paste from my CBV's get_context_data: context['data'] = assertion_dict context['dataitems'] = assertion_dict.items() return context copy and paste from my template: <h3>data dump</h3> {{data}} <h3>dataitems</h3> {% for key, value in dataitems %} {{ key }}: {{ value }} <br/> {% endfor %} <h3>data.items</h3> {% for key, value in data.items %} {{ key }}: {{ value }} <br/> {% endfor %} <h3>Not found test</h3> {{ i_dont_exist }} output: *

Allowing basic html markup in django

霸气de小男生 提交于 2019-12-10 16:33:54
问题 Im creating an app that will process user submitted content. I would like to enable users to make their text-based content look pretty with basic html markup i.e < i > < b > < br > . However I do want to prevent them from using things like script tags. Django will auto escape everything therefore it will also disable all safe markup. I can disable this by using: {{ somevar|safe }} or {% autoescape off %} However this will also enable all harmfull script tags. Django does provide the

Combine prefetch_related and annotate in Django

*爱你&永不变心* 提交于 2019-12-10 16:27:40
问题 I have three models class ModelA(models.Model): name = CharField(max_length=100) class ModelB(models.Model): modela = ForeignKey(ModelA) class ModelC(models.Model): modelb = ForeignKey(ModelB) amount = IntegerField() I can get the output name, number of model c objects ============== Some name, 312 Another name, 17 With the queryset ModelA.objects.all().prefetch_related('modelb_set', 'groupb_set__modelc_set') and template {% for modela in modela_list %} {% for modelb in modela.modelb_set.all

get key value from a dictionary django/python

我的梦境 提交于 2019-12-10 16:17:51
问题 How to print the value of a key from the key itself dict={} dict.update({'aa':1}) dict.update({'ab':1}) dict.update({'ac':1}) return render_to_response(t.html, context_instance=RequestContext(request, {'dict':dict})) So in this case i want to print the key alert('{{dict.aa}}'); i.e,without using any loop can we just print the key with the reference of aa in the the above example may some thing like if {{dict['aa']}} should give the value of aa 回答1: Never call a dictionary dict , that would

How to format date in different languages?

放肆的年华 提交于 2019-12-10 16:14:07
问题 I have a Django project with settings set to lang 'pl', in every template I use localized date format, for example: {{ item.date|date:'D, d N H:i:s e' }} result: Wt, 13 Lis 2012 22:00:00 But in only one template I must use format for lang 'en': Thu, 13 Nov 2012 22:00:00 GMT How can I accomplish this? 回答1: This helps for me: {% load i18n %} {% language 'en' %} {{ item.date|date:'D, d N H:i:s e' }} {% endlanguage %} For more details, see the Django online documentation. 回答2: This help for me,

Django not able to find the static files when using django-allauth

元气小坏坏 提交于 2019-12-10 16:06:40
问题 When I use allauth, everything seems to work fine except that Django is now unable to find the static files. Without allauth all the static files are being rendered. the settings for allauth requires to add TEMPLATE_CONTEXT_PROCESSORS = ( "allauth.context_processors.allauth", "allauth.account.context_processors.account" ) I did not have TEMPLATE_CONTEXT_PROCESSORS in my settings file earlier. Is there something that I am missing? How should I solve this problem. When I see the DEBUG console I

Django Can't Find App Templates

做~自己de王妃 提交于 2019-12-10 16:03:37
问题 I'm working through the official django 1.7 tutorial found here. Everything is going smoothly except django can't find the templates for apps. It finds templates that I put under workspace/mysite/templates but not under workspace/mysite/polls/templates. workspace is a folder I have in my home directory where I'm keeping all my web projects. My path is ~workspace/mysite/ and the project structure is `workspace | mysite | db.sqlite3 - manage.py - mysite - mysite_env - polls - templates` I'll

Can you use the verbatim tag with Django 1.5 on App Engine?

∥☆過路亽.° 提交于 2019-12-10 16:01:36
问题 In my app.yaml file I have: - name: django version: "1.5" which I assume means, use Django 1.5. 1.5 includes the verbatim tag, but when I try to use it I get: TemplateSyntaxError: 'verbatim' is not a valid tag library: Template library verbatim not found, tried google.appengine._internal.django.templatetags.verbatim Any idea how to enable this feature or is it just not included with app engine, I am using 1.8.9. Thanks! 回答1: I don't think it works. When I tried to do this, I got this