django-templates

How do I get a “debug” variable in my Django template context?

你离开我真会死。 提交于 2019-12-22 02:00:10
问题 According to this SO post: How to check the TEMPLATE_DEBUG flag in a django template? if: A) my settings.py file has: TEMPLATE_CONTEXT_PROCESSORS = ['django.core.context_processors.debug',... and B) I use a RequestContext (as opposed to a Context) I should have a "debug" variable to my template context. However, I don't: when I do {{debug}} in a template, it renders as nothing (""). Is there anything else I'm missing that is necessary to get a "debug" var in the template context? 回答1: You

Accessing query set object in django template

本小妞迷上赌 提交于 2019-12-22 01:34:16
问题 I have two models, named as Human and Animal . The primary key of Human is foreign key in the Animal model. Both has 3 columns each. Human model has c, e, r columns. Animal model has l, i, p columns. I am running a django query on Human model, like this. result = Human.objects.filter().order_by('r') result is an queryset object. This object is sent from my view file to a django template page. Inside template page I am looping through result and displaying the column values. Now what i want to

How to use images loaded with webpack in django templates?

落花浮王杯 提交于 2019-12-22 01:32:44
问题 I am using Webpack 2 and use url-loader to load all of my images. before using webpack, I used the static template tag like this: <img src="{% static "img.png" %}" ... /> and now webpack renames all of the images to some hash and ext like this: img.png becomes img-[somehash].png . ( I use this for cache invalidation ). the problem is how to load the new image (with the hash) in django templates ?! thanks in advance. 回答1: How about passing correct path in context data? In Django view you are

django serving static css files

有些话、适合烂在心里 提交于 2019-12-22 00:58:58
问题 I am relatively new to Django development.I have a css file inside a /static/css directory. When I try to run the url no CSS is applied to my template. the python manage.py runserver window shows following error [01/Jan/2013 20:00:40] "GET /home/prat/PROJECT_ROOT/SOURCE_ROOT/static/css/Style.css HTTP/1.1" 404 2207 Can someone please point me how to debug this. I have read multiple stackoverflow questions and added the following setting in my settings.py. PROJECT_R = os.path.abspath(os.path

webapp2, Jinja2: how to cut large html file into multiple html files

若如初见. 提交于 2019-12-21 22:00:52
问题 When I blog, I like to separate each blog-post into its own .html file (is that ok?) This prevents the file getting too big, and makes it easy to go back and edit a previously written blog post if need be. Occasionally the blog post will contain css/js/ajax/template variables. But on my website, I like all the blog posts on one page (so I can scroll through them all, instead of going to a separate page for each post) Here is an html file that contains two blog posts: {% extends "base.html" %}

Issues with feeding data into database when using for loop

怎甘沉沦 提交于 2019-12-21 21:32:37
问题 In my template I have used for loop for some fields <div class="register_div"> <p>Title:</p> <p>{{ form.title }}</p> </div> <div class="register_div"> <p>Upload Images :</p> <p>{{ form.image }}</p> </div> {% for item in product %} <div class="register_div"> <p>{{ item.Name }} <input type="text" name="custom[{{item.id}}]"/></p> </div> {% endfor %} <div class="register_div"> <p>Price:</p> <p>{{ form.price }}</p> </div> As code shows there is one field which using for loops if that field has

How to override my template instead of django admin panel for reset password?

天大地大妈咪最大 提交于 2019-12-21 20:41:18
问题 I am following this blog to reset the user password in Django. It is working perfectly. But the problem is that I want to show my template instead of the Django admin panel when resetting the password or confirming the mail. How can I achieve it? This is my urls.py file url(r'^password_reset/$', password_reset , name='password_reset_reset1'), url(r'^password_reset/done/$', password_reset_done, name='password_reset_done'), url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0

Django: Why does this custom model field not behave as expected?

橙三吉。 提交于 2019-12-21 18:29:25
问题 The following field is meant to format money as a two places decimal (quantized). You can see that it returns a <decimal>.quantize(TWOPLACES) version of the stored decimal. When I view this in the Django admin however, it doesn't do that. If I put in 50 to a field that is using CurrencyField() and view it in the admin, I get 50 vs 50.00 . Why is that? from django.db import models from decimal import Decimal class CurrencyField(models.DecimalField): """ Only changes output into a quantized

Django: how to get the name of the template being rendered

人走茶凉 提交于 2019-12-21 12:35:40
问题 I'm implementing a bootstrap navbar as show in this example here Items in a navbar are <li>'s , the "selected" item has the attribute class="active" : <li class="active"> <a href="#"> Link1 </a> </li> <li> <a href="#"> Link2 </a> </li> In Django these items will be within a template, which gets included by any templates that are supposed to display the navbar. I'm thinking about doing it this way: <li> <a href="/" class="{% if template_name == "home.djhtml" %}active{% endif %}"> Home </a> <

What dose the curly-brace and percent sign mean in html?

送分小仙女□ 提交于 2019-12-21 09:28:20
问题 I am learning how to develop website in Django framework. There is something I don't understand about the template html file. I saw the tutorial used the curly-braces( <% if ... %> <% endif %> etc.) to embed logic in the code. But when I try to use this syntax in a non-Django server(Apache) this syntax was not interpreted and I can see my <% if ... %> ... right on my page. I dont know why this is. So this syntax is not a part if HTML but rather a part of Django so it can be interpreted by it?