django-templates

Applying bootstrap styles to django forms

99封情书 提交于 2019-12-27 11:25:09
问题 I want to use bootstrap to get a decent website design, unfortunately I don't know how style the form fields. I am talking about this: <form class="form-horizontal" method="POST" action="."> {% csrf_token %} {{ form.title.label }} {{ form.title }} </form> How is one supposed to design this?? I tried this: <form class="form-horizontal" method="POST" action="."> {% csrf_token %} <div class="form-control"> {{ form.title.label }} {{ form.title }} </div> </form> This obviously didn't gave me the

Performing a getattr() style lookup in a django template

好久不见. 提交于 2019-12-27 10:40:14
问题 Python's getattr() method is useful when you don't know the name of a certain attribute in advance. This functionality would also come in handy in templates, but I've never figured out a way to do it. Is there a built-in tag or non-built-in tag that can perform dynamic attribute lookups? 回答1: I also had to write this code as a custom template tag recently. To handle all look-up scenarios, it first does a standard attribute look-up, then tries to do a dictionary look-up, then tries a getitem

AngularJS with Django - Conflicting template tags

僤鯓⒐⒋嵵緔 提交于 2019-12-27 08:56:19
问题 I want to use AngularJS with Django however they both use {{ }} as their template tags. Is there an easy way to change one of the two to use some other custom templating tag? 回答1: For Angular 1.0 you should use the $interpolateProvider apis to configure the interpolation symbols: http://docs.angularjs.org/api/ng.$interpolateProvider. Something like this should do the trick: myModule.config(function($interpolateProvider) { $interpolateProvider.startSymbol('{[{'); $interpolateProvider.endSymbol

How can I make a Google Map marker redirect to a URL?

孤街醉人 提交于 2019-12-25 18:48:10
问题 Here is my html: {% extends 'base.html' %} {% block title %}Home{% endblock %} {% block content %} <style> /* Set the size of the div element that contains the map */ #map { height: 700px; /* The height is 400 pixels */ width: 100%; /* The width is the width of the web page */ } </style> <!--The div element for the map --> flavor <div id="map"></div> <script> // Initialize and add the map function initMap() { var map = new google.maps.Map( document.getElementById('map'), {zoom: 4, center: {

Django {% url %} reverse not working

流过昼夜 提交于 2019-12-25 18:28:45
问题 I have a view in a Django 1.4 project: def index(request): print reverse('menus_index') latest_menu_list = Menu.objects.all().order_by('name') return render_to_response('menus/index.html', {'latest_menu_list': latest_menu_list}) This works as expected and prints out the reversed URL which is /menus/. Inside of the index.html template (which is called by this view) I have: {% url menus_index %} Which causes a NoReverseMatch at /menus/ error. Reverse for '' with arguments '()' and keyword

Django: modifying data with user input through custom template tag?

夙愿已清 提交于 2019-12-25 16:51:31
问题 Is it possible to modify data through custom template tag in Django? More specifically, I have a model named Shift whose data I want to display in a calendar form. I figured using a custom inclusion tag is the best way to go about it, but I also want users to be able to click on a shift and buy/sell the shift (thus modifying the database). My guess is that you can't do this with an inclusion tag, but if I were to write a different type of custom template tag from the ground up, would this be

How to print list according to index in Django template?

徘徊边缘 提交于 2019-12-25 14:47:34
问题 I have a query like this in Django template: shared_username = [User.objects.filter(id__in= Share.objects.filter(users_id = log_id, files__file_name=k).values_list('shared_user_id', flat=True)).values_list('username') for k in file1] It gives the output like this: [[(u'fgdg',), (u'fsddfa',)], [(u'fgdg',)]] The first list [(u'fgdg',), (u'fsddfa',)] gives the shared_username of the first list and so on. I want to show the username for a file to the file. File Name Type Size Shared On Shared

How to print list according to index in Django template?

帅比萌擦擦* 提交于 2019-12-25 14:47:12
问题 I have a query like this in Django template: shared_username = [User.objects.filter(id__in= Share.objects.filter(users_id = log_id, files__file_name=k).values_list('shared_user_id', flat=True)).values_list('username') for k in file1] It gives the output like this: [[(u'fgdg',), (u'fsddfa',)], [(u'fgdg',)]] The first list [(u'fgdg',), (u'fsddfa',)] gives the shared_username of the first list and so on. I want to show the username for a file to the file. File Name Type Size Shared On Shared

How to print list according to index in Django template?

不羁岁月 提交于 2019-12-25 14:47:11
问题 I have a query like this in Django template: shared_username = [User.objects.filter(id__in= Share.objects.filter(users_id = log_id, files__file_name=k).values_list('shared_user_id', flat=True)).values_list('username') for k in file1] It gives the output like this: [[(u'fgdg',), (u'fsddfa',)], [(u'fgdg',)]] The first list [(u'fgdg',), (u'fsddfa',)] gives the shared_username of the first list and so on. I want to show the username for a file to the file. File Name Type Size Shared On Shared

Django Template not loading

为君一笑 提交于 2019-12-25 14:09:35
问题 I have a project named 'src' and app named 'app' and i have a template folder inside my app. And inside my template folder i have another folder named pages and my html pages(base.html and view.html) are resides there. My view.py is below from django.shortcuts import render from django.utils import timezone # Create your views here. def home(request): return render(request, "pages/base.html", {}) and urls.py from django.conf import settings from django.conf.urls import include, url from