django-templates

How to move singup\signin templates into dropdown menu?

℡╲_俬逩灬. 提交于 2019-12-30 07:54:07
问题 I have a fixed navigation and I want to add dropdown box where users can singup\in (as Twitter uses). I tried: # project/tempates/signup.html {% load i18n %} {% load account socialaccount %} {% block head_title %}{% trans "Signup" %}{% endblock %} {% block content %} <h1>{% trans "Sign Up" %}</h1> <p>{% blocktrans %}Already have an account? Then please <a href="{{ login_url }}">sign in</a>.{% endblocktrans %}</p> <form class="signup" id="signup_form" method="post" action="{% url 'account

Google app engine ReferenceProperty relationships

▼魔方 西西 提交于 2019-12-30 07:40:59
问题 I'm trying to get my models related using ReferenceProperty, but not have a huge amount of luck. I have 3 levels: Group, Topic, then Pros, and Cons. As in a Group houses many topics, and within each topic could be many Pros and Cons. I am able to store new Groups nice and fine, but I don't have any idea how to store topics underneath these groups. I want to link from a page with a link "New topic" underneath each group, that takes them to a simple form (1 field for now). Obviously the URL

Django: logging template errors

做~自己de王妃 提交于 2019-12-30 06:44:32
问题 When I make an error in a django template {{placeholder}} , I get no error, just blank space in the output where I was expecting content. Is there a way to see something in my logs when this occurs, preferably using logging.warning or logging.error ? 回答1: The only thing Django provides for handling unknown context variables in TEMPLATE_STRING_IF_INVALID. You're going to have to do some deeper hacking of the template engine if you want better than that. 回答2: Yes, there is. Just add in your

How do I register custom filter in Google App Engine template system?

对着背影说爱祢 提交于 2019-12-30 06:41:46
问题 According to Django documentation I've registered my filter: from google.appengine.ext.webapp import template # ... register = template.create_template_register() @register.filter(name='wld') def wld(result): if result == 1 : return "win" if result == 0 : return "loss" if result == 0.5 : return "draw" return "unknown" self.response.out.write(template.render("player.html", template_values)) somewhere in the template I have code: {{result|wld}} and when I try to render my template, I get the

Django: use render_to_response and set cookie

百般思念 提交于 2019-12-30 04:15:12
问题 Currently, I'm using render_to_response(template_name, locals(), context-etc..) Trying to set a cookie right now and I'm wondering if I can do it with render_to_response . All the examples I see are using HttpResponse object. They set the cookie in the response object, like this response = HttpResponseObject(html) response.set_cookie("favorite_color",request.GET["favorite_color"]) return response Wondering if I can set cookie with render_to_response , so I can continue using locals() Thank

Get first item of QuerySet in template

爱⌒轻易说出口 提交于 2019-12-30 03:47:12
问题 In my blog app I want to display a list of blog posts and the first image connected to this post. Now I do it this way: {% for image in entry.image_set.all|slice:"1" %} <img src="{{ image.get_absolute_url }}"> {% endfor %} Is there a template shortcut I don't know about, or maybe I should just write my own Manager? 回答1: Not any shorter, but you could use first: {% with entry.image_set.all|first as image %} <img src="{{ image.get_absolute_url }}"> {% endwith %} 回答2: Since Django 1.6 you can do

Whats easiest way to use filter_horizontal outside of the Admin in Django

谁说胖子不能爱 提交于 2019-12-30 03:14:29
问题 I have a non-admin form in which I'd like to use filter_horizontal on. I have read this which does much more than what I want (I only want the filter_horizontal). I wanted to check to see if anyone has come up with a simpler (more current) way to just implement the filter_horizontal. So here is the code: class County(models.Model): """County Names""" name = models.CharField(max_length=64) state = USStateField(null=True) class Company(models.Model): """The basics of a company""" name = models

Jinja2 templates using Django template tags

爷,独闯天下 提交于 2019-12-29 08:50:53
问题 I'm using Jinja2 on a new project, but would like to use the django-socialregistration app, which relies on Django template tags. Jinja2 doesn't play nicely with template tags, so I'm wondering if there's a quick workaround? Template tags: {% load facebook_tags %} {% facebook_button %} {% facebook_js %} This previous question addresses the same topic for Mako, but I'm having trouble adapting it to work with Jinja2. The following is my attempt at an adaptation (non-working): {% from django

Django site in developement: CSS not loading for all pages

删除回忆录丶 提交于 2019-12-29 08:03:21
问题 I'm afraid I'm at a loss here, I checked out some similar questions but none of them seem to apply. I am running the django developement server on my laptop. I use it to serve static files as well. I have a folder in the static root which contains the CSS for 2 templates both called base.html. this is the head section of the one that works: <head> <title>| Entries | Latest entries</title> <link rel="stylesheet" type="text/css" href="/static/css/serenity.css" /> </head> here is the one which

Nested loop in Django template

橙三吉。 提交于 2019-12-29 07:01:11
问题 I can't get my head around this. I need to somehow access the object in the parent loop but I'm not sure how. Here is what I've come up with so far. I marked the problematic area in the code with XXX : Template: {% for item in ingrcat %} <h2>{{ item.name }}</h2> <ul> {% for ingr in XXX %} <li><a href="#" id="i{{ ingr.id }}">{{ ingr.name }}</a></li> {% endfor %} </ul> {% endfor %} XXX - should be a list of ingredients belonging to the ingredience category which is currently being looped