django-templates

django - how to reuse a template for nearly identical models?

点点圈 提交于 2019-12-05 21:16:26
Still fairly new to django and python. I've defined two nearly identical models that inherit from a base class: class addressbook(models.Model): name = models.CharField(max_length=50) class company(addressbook): address = models.CharField(max_length=50) class contact(addressbook): telephone - models.CharField(max_length=30) I want to do very similar things with company and contact objects. However in my templates it looks like I need to use separate templates for each object since to access the members in the object I have to use something like {{ blah.name }} {{ blah.address}} in one but {{

Adding Google Map Markers with DJango Template Tags in Javascript

爷,独闯天下 提交于 2019-12-05 19:58:44
I am trying to add a bunch of map markers to a map using Django template tag variables as the latitude and longitude but things aren't working too well. Here is what I have in the view javascript code. I load the code in as an external JS file. Here is what i have to initialize everything. Also when I did this the google map didn't even show up any more. It disappeared. function initialize() { var latLng = new google.maps.LatLng(41.85, -87.65); map = new google.maps.Map(document.getElementById('map_canvas'), { zoom: 8, center: latLng, mapTypeId: google.maps.MapTypeId.ROADMAP }); marker = new

django csrf RequestContext

橙三吉。 提交于 2019-12-05 19:42:07
问题 If I include {% csrf_token%} in my form template and import RequestContext in my view, do I have to include anything else in my view or will the csrf protection be taken care of just be the following: from django.shortcuts import render_to_response from django import forms from django.http import HttpResponseRedirect from django.template import Template, RequestContext from dash.forms import GradeForm def register(request): if request.method == 'POST': form = GradeForm(data=request.POST) if

Django - Admin - How to override change_list template for Model Proxy?

有些话、适合烂在心里 提交于 2019-12-05 19:22:22
I made a simple Django app. I have one model "Visitor". My goal is to have two tables appear in the Django admin. One with all of the visitors and one with only those for today. I got everything working with the code below by following these instructions . But I'm not sure how to override just the change_list.html for just VisitorExpectedTodayProxy. I tried following the instructions here and I created Site/templates/admin/VisitorLog/VisitorExpectedTodayProxy/change_list.html and made my changes there, but it doesn't seem to be picking it up. Models.py class Visitor(models.Model): visit

How to remove spaces and empty lines from HTML in Django?

☆樱花仙子☆ 提交于 2019-12-05 19:00:50
I use Python 3.4 + Django 1.7.1 with Eclipse - PyDev and I use AcroEdit to edit HTML. I think AcroEdit uses two soft spaces for indent. I made a custom template tag named custom_tag in custom_tag_library.py like: # -*- coding: utf-8 -*- from django import template from _ast import Num register = template.Library() @register.inclusion_tag('custom_tag.html') def custom_tag(content): return {'content': content, 'children': content.children.all()} and for custom_tag.html : {% load custom_tag_library %} <div class = 'a'> {{ content.name }} {% if children %} <div class = 'b'> {% for child in

django sort the query elements in a weekly monthly daily fashion

六月ゝ 毕业季﹏ 提交于 2019-12-05 18:29:21
I am getting a list of people and the tests they have taken from an api in the same project. I would like the user to have an option to see the number of tests that have taken place in a city with three options - daily/weekly/monthly. models.py class City(models.Model): city_name=models.CharField(max_length=100,default='',blank=False) class Person(models.Model): title = models.CharField(max_length=3,default="mr",blank=False) name = models.CharField(max_length=50,default='',blank=False) address = models.CharField(max_length=200,default='',blank=False) city = models.ForeignKey(City) class Test

Can not use unicode string in django template

ぐ巨炮叔叔 提交于 2019-12-05 18:01:17
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 in my project. Please help me, thanks! You can define into your HTML tag! <meta http-equiv="Content

Link stylesheets to Django template

痞子三分冷 提交于 2019-12-05 17:37:28
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 patterns, include, url from bible import views from django.contrib import admin from django.conf.urls

CSS Templating system for Django / Python?

↘锁芯ラ 提交于 2019-12-05 16:52:35
I'm wondering if there is anything like Django's HTML templating system, for for CSS.. my searches on this aren't turning up anything of use. I am aware of things like SASS and CleverCSS but, as far as I can tell, these still don't solve my issue as I want to dynamically generate a CSS file based on certain conditions, so that a different CSS file would be served based on a specific user session... I want to minimize the use of javascript / AJAX for some things (since its for a legacy system running in some hospital where they're still using IE 6 ), also I have an interest in possibly

django: can we do loader.get_template('my_template.txt')?

左心房为你撑大大i 提交于 2019-12-05 15:26:29
I want to use django template to process plain text file, and tried this: from django.template import loader, Context t = loader.get_template('my_template.txt') however, it works for this: from django.template import loader, Context t = loader.get_template('my_template.html') Can we load txt files using django template loader? how? thanks. As @Seth commented I don't see any reason why this shouldn't work. Django doesn't care about the extension of the file. You can very well load my_template.foo . Check the following: The file is indeed present where it should be. If it is in a subdirectory