django-templates

Get datepicker defaultdate from string/django object

 ̄綄美尐妖づ 提交于 2019-12-11 00:47:56
问题 I am a total (like no-experience-whatsoever) noob in jquery and Javascript, and what I would like to do is the following: I pass an article-object to my template that has date-information stored in it. I can access and display that information with {{ article.pubdate }} . Is it possible to set the defaultDate option of datepicker to the article date? How would I go about that? Thanks for any pointers! Update : Some more information about {{ article.pubdate }} : It is a datetime object. The

manytomany field in form with checkboxes insted select field in django template

非 Y 不嫁゛ 提交于 2019-12-10 23:37:32
问题 I have model with ManyToManyField. Now I need form but don't need select field in template. class Foo(models.Model): name = models.CharField(max_length=50) short_description = models.CharField(max_length=100) price = models.IntegerField() def __unicode__(self): return self.name class Bar(models.Model): foo = models.ManyToManyField(Foo, blank=True, null=True, related_name='foos') def __unicode__(self): return unicode(self.id) What I really need is to display all data from the Foo model with

Displaying page content using django-page-cms

a 夏天 提交于 2019-12-10 23:33:11
问题 I would like to display some content located in my models in some of my template pages. I am using django-page cms In the documentation views are not used to display content. Instead ready made template tags are used. http://packages.python.org/django-page-cms/display-content.html I do not understand a word of this. Please Bear with me I am new. All I want to do is display some info located in my models inside a template this manner.. {% if latest_news_list %} {% for news in latest_news_list

how to get python to not append L to longs or ignore in django template

百般思念 提交于 2019-12-10 23:30:12
问题 Is there a way to get around python appending an "L" to Ints short of casting every time they come out of the database? (Note: I'm using Mysql) OR, is there a way to ignore the L in django templates? (I keep getting invalid formatting errors because of this, but I'd rather not do list comprehension/casting EVERY time) e.g. I have a dict with the object's pk as the key and I get the following in firebug: invalid property id alert({183L: <Vote: colleen: 1 on Which best describes your wardrobe

How to use Django template tag within another tag?

筅森魡賤 提交于 2019-12-10 23:23:13
问题 I have a Django website that I'm trying to get internationalized. The image files are all encoded with the language code of two letters. So when a user switches the language, the references to image files are updated with the language code in templates as follows: <img src="{% static 'website/images/contact_us_{{ LANGUAGE_CODE }}.png' %}"> Problem is, I have to have a tag as well for the path of static content. What is an elegant way to solve this? 回答1: Per @MarAja suggestion, I followed his

Load Django “static” template tag library globally without explicitly loading it in every file

大城市里の小女人 提交于 2019-12-10 21:27:59
问题 I want to use the static tag in templates like so: <img src="{% static "img/test.jpg" %}"> I've found that that requires me to put {% load static %} at the beginning of every template file. Since I'm using it everywhere, I would like it to be a globally available tag so I don't need to put {% load static %} to use it. In my settings I do have: TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.static', ) I saw both of these questions: Make django static tag globally available and

How To Properly Customize Django LoginView

随声附和 提交于 2019-12-10 20:42:32
问题 I am trying to figure out how to customize the django LoginView based on whether or not it's the user's first time logging on for the day. I have my LoginView currently set up so that it defaults to the LOGIN_REDIRECT_URL = "book:author" in my settings.py file. This works flawlessly. When a user logins in and is successfully authenticated, they are redirected to "book:author" as I would expect. What I'm trying to do is if this is the first time the user has logged in for the day, direct them

Is it possible to load a custom template tag in base and use it in extented templates

余生长醉 提交于 2019-12-10 20:31:34
问题 I loaded a custom template tag note_extras.py in base.html . base.html <div id="wrap"> {% load note_extras %} {% block content %} {% endblock %} </div><!--wrap--> but it is not accessible at templates which is an extend of base.html ie:: home.html {% extends "base.html" %} {% block content %} <div class="container"> {% create_tagmenu request.user.pk %} </div> {% endblock %} it is working fine if i load note_extras in home.html ie: {% extends "base.html" %} {% load note_extras %} .... 回答1: In

Django not loading CSS?

▼魔方 西西 提交于 2019-12-10 19:49:37
问题 This is my urls.py import os.path site_media = os.path.join( os.path.dirname(__file__), 'site_media' ) urlpatterns = patterns('', url(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': site_media }), ) My site_media folder and style.css file is in myProjectFolder/myApp/static/site_media/css/style.css and in my base.html template (all my other templates extend off of this base.html template) this is what I have: <head> <title>{% block title %}{% endblock %}</title>

Summarizing inside a Django template

霸气de小男生 提交于 2019-12-10 19:47:27
问题 I have the following template in django, i want to get the totals of the last 2 columns for each of my document objects {% for documento in documentos %} {% for cuenta in documento.cuentasxdocumento_set.all %} <tr {% cycle 'class="gray"' '' %} > {% if forloop.first %} <td>{{ documento.fecha_creacion.date }}</td> <td>{{ cuenta.cuenta.nombre }}</td> <td> {% if cuenta.monto >= 0 %} {{ cuenta.monto}} {% endif %} </td> <td> {% if cuenta.monto <= 0 %} {{ cuenta.monto }} {% endif %} </td> {% else %}