django-templates

How to use Django template as a component?

北城余情 提交于 2019-12-13 03:13:12
问题 I have 5 templates: index.html, detail.html, tag.html, login.html, register.html and a base.html All 5 templates will extend base.html . index.html, detail.html, tags.html have a same <section>...</section> html code section with the same data from backend.I want to add this section to base.html , so that don't need to repeat it 3 times in 3 different templates. But the problem is,the login.html and register.html do need this section. I know if it is React.js or Vue.js it will be very easy to

Search input on every pages django

半世苍凉 提交于 2019-12-13 03:09:19
问题 I want to add search in my website and I want search from my pages (html) ** note : i want take the label tag , I mean I have label tag called test and when user write in search bar test I want to show the label to user. always I got this message in result page : not found So, I created this form in home html page <form class="" action="{% url 'test_search_page'%}" method="get"> <div class="md-form mt-0 search-bar" id="search_form"> <input id="search_box" autocomplete="off" onkeyup=

How to use Django build-in comment framework on any template

北战南征 提交于 2019-12-13 03:06:30
问题 I just begin to study Django build-in comments function. at first I think the comment template should work well on any page just with get_comment_form or render_comment_form .but now it really annoying when i add these code to a ordinary page. It doesn't work. maybe in a other word. I don't know how to specify the object to attached to when it come to a normal page. below is the detail message : models.py class Entry(models.Model): title = models.CharField(max_length=250) body = models

How can display the label of non-editable fields in django template

*爱你&永不变心* 提交于 2019-12-13 02:54:18
问题 I have this field in my model: created_date = models.DateTimeField(null=True, blank=True,editable=False, verbose_name=_("Something to show... ")) In accordance with this document ,I show the value of this field by: form.instance.created_date I see these links: 1,2,3,4 and this docucment of django. But none of them talk about showing the label (Or verbos_name ) of non-editable fields in template. Also I test these possible modes: 1. form.instance.created_date.label_tag 2. form.instance.created

Math comparison operating in Django .96 templates

若如初见. 提交于 2019-12-13 02:14:15
问题 i want to compare do simple math in django template like {% forloop.counter > 5 %} {% endfor %} how do i achieve this? 回答1: This isn't really possible, because Django deliberately provides a very limited syntax, which doesn't include math operators. You could do this by writing a custom template filter, but it's a poor idea - you'd be better off preprocessing the data before passing it in so you don't require the math operator. That's certainly what Django wants you to do, anyway. 来源: https:/

How to change 'Django Administration' name to a custom name in admin login and admin page

我的梦境 提交于 2019-12-13 02:12:05
问题 I am trying to change the name of django administration to custom name how do i do that.Is there any way completely customize the admin page give it more professional look 回答1: There are several ways to customize the Django admin. First of all, you can always override any template (see docs : https://docs.djangoproject.com/en/1.6/intro/tutorial02/#customize-the-admin-look-and-feel it is actually using this very case as example) Starting with Django 1.7, it will be accessible via settings :

Django inclusion_tag contents not displaying

三世轮回 提交于 2019-12-13 02:11:57
问题 I cannot get the contents of an inclusion_tag to display. I am not getting an errors so i know that the tag is registering and I am almost certain that it is loading correctly. The tag is created in crudapp/templatetags/crudapp_tags.py from django import template register = template.Library() @register.inclusion_tag("forum.html") def results(poll): form = 'blah' return {'form': form} templates/forum.html {% extends 'index.html' %} {% load crudapp_tags %} {% results poll %} <p>aaa</p> {% block

How to implement Post/Redirect/Get in django pagination?

笑着哭i 提交于 2019-12-13 01:15:30
问题 I have a view that filters out results for a posted search form: def profile_advanced_search(request): args = {} if request.method == "POST": form = AdvancedSearchForm(request.POST) qs=[] if form.is_valid(): cd = form.cleaned_data s_country=cd['country'] s_province=cd['province'] s_city = cd['city'] if s_country: qs.append(Q(country__icontains = s_country)) if s_province: qs.append( Q(province__icontains=s_province)) if s_city: qs.append( Q(city__icontains=s_city)) f = None for q in qs: if f

Override a django third-party application template through extend

两盒软妹~` 提交于 2019-12-13 00:45:33
问题 I'm using third-party apps (through Pinax), and I am trying to override a template file that the third-party template extends from. That is -- Third party app: templates/app/a.html templates/base.html My project: templates/app/b.html templates/base.html Where I've copied and modified base.html from the third-party app for use in my own project and both the third-party app/a.html and my own app/b.html do {% extends "base.html" %} . The current behavior is that when app/a.html extends base.html

Accessing session variable in Django template with Google App Engine (Webapp) - Python

谁说胖子不能爱 提交于 2019-12-12 23:14:59
问题 I have a Django template as my front-end. At the back-end, I used the sessions provided from Gaeutilities to store a variable (email). Front-end: {% if session.Email %} <div id="entersite">WELCOME <em>{{session.Email}}</em></div> {% else %} <div id= "entersite"><a href="/login/" id= "entersite">Enter the Site</a></div> {% endif %} Back-end: self.session = Session() self.session['email'] = email temp = os.path.join(os.path.dirname(__file__),'templates/index.htm') outstr = template.render(temp,