django-templates

twitter bootstrap dropdown not working in django template

一个人想着一个人 提交于 2019-12-24 08:37:20
问题 Thanks for trying to help in advance! My problem is that twitter bootstrap's dropdown menu (for navbar) doesn't work for me and I am very lost now. My header code (so yes, I do include their .js and call it): <head> <title>{% block title %}User test{% endblock %}</title> <!--for IE6-8 support of HTML elements --> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script type="text/javascript" src="http://twitter.github.com/bootstrap

Django Use Static files URL in Static Files

吃可爱长大的小学妹 提交于 2019-12-24 08:34:12
问题 I want to use a custom font in my style.css file that will get served by StaticFiles I know I can hard code it with something like this: @font-face { font-family:"NotoSansArabic"; font-style:normal; src: url("/static/myApp/fonts/NotoSansArabicUI-ExtraBold.ttf") format("truetype") } Im looking for something like: {% static 'myApp/fonts/NotoSansArabicUI-ExtraBold.ttf' %} Is there other way to do this? Both font and style.css are served as Static 回答1: For {% static %} to work you need to have a

Render a list of foreign key in template

谁说胖子不能爱 提交于 2019-12-24 08:24:39
问题 Models class Head_of_department(models.Model): first_name = models.CharField(max_length=200) last_name = models.CharField(max_length=200) email = models.CharField(max_length=30) def __str__(self): return self.first_name class Employee(models.Model): first_name = models.CharField(max_length=200, unique=True) last_name = models.CharField(max_length=200, unique=True) head_of_department = models.ForeignKey('Head_of_department', on_delete=models.SET_NULL, blank=True, null=True) email = models

Django Compressor with dynamic LESS file raises a FilterError(err)

醉酒当歌 提交于 2019-12-24 07:17:34
问题 I had to come up with quite a complicated setup to enable database based styling options for users. Users enter styles (like background color, font face, etc...) in the django admin backend. I am creating a dynamic LESS file by rendering a template view as plain text view like so: views.py: class PlainTextView(TemplateView): """ Write customized settings into a special less file to overwrite the standard styling """ template_name = 'custom_stylesheet.txt' def get_context_data(self, **kwargs):

Django: include external include files

一个人想着一个人 提交于 2019-12-24 06:20:29
问题 Im building a web app which will be part of an existing static website. I'd prefer to use the header and footer from the current site which are static .inc include files. Is there a way to include these files something like: {% include 'http://www.mysote.com/inc/footer.inc' %} 回答1: There isn't a built-in way to do this in Django, but it would be a really easy template tag to write on your own (there's a decent chance someone has already written such a thing, though a quick search didn't turn

How to resolve conflict between Embers Handlebar and Django Template

偶尔善良 提交于 2019-12-24 05:54:54
问题 I am using Ember and Django and quickly found out that the template delimiter in Handlebar conflicts with that of Django Templates. So i intsalled Django-embers http://pypi.python.org/pypi/django-ember/0.1 But It just not seem to work properly. This is the problem: If I have something like this in APP.js var Ab = Em.Application.create({ appDescription : 'HelloWorldApp' }); I can easily render it in the template like this {% load ember %} {% handlebars "" %} {{Ab.appDescription}} {%

Is 'if element in aList' possible with Django templates?

流过昼夜 提交于 2019-12-24 05:33:33
问题 Does something like the python if "a" in ["a", "b", "c"]: pass exist in Django templates? If not, is there an easy way to implement it? 回答1: This is something you usually do in your view functions. aList = ["a", "b", "c"] listAndFlags = [ (item,item in aList) for item in someQuerySet ] Now you have a simple two-element list that you can display {% for item, flag in someList %} <tr><td class="{{flag}}">{{item}}</td></tr> {% endfor %} 回答2: Not directly, there is no if x in iterable template tag

Django Admin Changing Inline Admin Form based on class type

人走茶凉 提交于 2019-12-24 05:12:17
问题 I asked some questions about Django inheritance in a previous question. Now I am trying to figure out how to get the admin interface to work with it. If I had some models like this: class ContentItem(models.Model): title = models.CharField(max_length=1000) page_order = models.IntegerField() last_update_date = models.DateTimeField(default=datetime.now()) class Meta: abstract = True ordering = ['page_order', 'last_update_date', 'title'] class LinkContent(ContentItem): url = models.URLField()

Django multiple forms with one submit button

≡放荡痞女 提交于 2019-12-24 04:35:07
问题 I have many "polls" in my webapp, in which I have them all showing up on the same page, but cannot figure out how to have one submit(vote) button for all of the forms. As of right now, they all have their own vote buttons for each question, but I would like just one at the bottom to submit everything. My HTML code for this template is as follows: {% if latest_question_list %} {% for question in latest_question_list %} <h2>{{ question.question.text }}</h2> <form action="{% url 'polls:vote'

How to get site name in django template?

最后都变了- 提交于 2019-12-24 03:59:50
问题 In the admin interface, I can see how I can specify the name of the site. But I can't find the documentation for how to use it in my templates. 回答1: You can set site name in class requests.RequestSite . It is a class that shares the primary interface of Site (i.e., it has a domain and name attributes) but gets its data from a Django HttpRequest object rather than from a database. You have to use __init__(request) in it to set the name and domain attributes to the value of get_host(). In