django-templates

How create a custom form in django with database values

余生长醉 提交于 2020-01-25 06:50:14
问题 model.py class Venue(models.Model): venue_Name = models.CharField(max_length=100) place = models.CharField(max_length=50) rent = models.IntegerField() parking_area = models.IntegerField() class Decoration(models.Model): rate = models.IntegerField() I have printed the values in database as radio buttons what i want to do is that i want to get the total sum i.e venue.rent + decoration.rate and print it in another page What shoud i give in form action I'm not that familiar with forms. html <form

Django template is not changed after update (possible cache)

不问归期 提交于 2020-01-25 06:24:04
问题 I have a problem with Django. Possibly with it's cache. Version 1.11 I use template in urlpatterns like : urlpatterns = [ url(r'^service_preview/', include(serviceprev_urls, namespace = 'service_preview')), url(r'^service_preview/',TemplateView.as_view(template_name='service_preview.html')), ] After a lot of updates, applied to my template, the changes stop appearing in user's browser. I have actual template in my templates folder and some previous version when preview source code in browser.

How to include a form in multiple templates

跟風遠走 提交于 2020-01-25 00:39:40
问题 I have a Django app with two types of users, lets call them A and B. The two user types have different navigation bars. User type A has a link in their navigation bar to allow them to send a message. The send message form comes up in an overlay, so the form needs to be present in every template, or fetched over AJAX. These users can send a message from any/every page on the site, and each page has its own view. If a message has errors, users should be returned to the same page they were on,

DISTINCT ON fields is not supported by this database backend

无人久伴 提交于 2020-01-24 23:32:47
问题 I am using distinct to get the distinct latest values but it is giving me an error: DISTINCT ON fields is not supported by this database backend views.py class ReportView(LoginRequiredMixin, generic.TemplateView): template_name = 'admin/clock/report.html' def get_context_data(self, **kwargs): context = super(ReportView, self).get_context_data(**kwargs) context['reports'] = TimesheetEntry.objects.filter( timesheet_jobs__job_company = self.request.user.userprofile.user_company, ).distinct(

How to use a custom template tag in base.html

对着背影说爱祢 提交于 2020-01-24 13:03:30
问题 . is my project root, where manage.py resides. I have a base template at ./templates/base.html . I have a custom template tag in ./app/templatetags/mytags.py from django import template register = template.Library() @register.unread_tag def get_unread(user): return user.notification_set.filter(viewed=False).count() How do I make this tag usable for base.html, from which all app-level templates inherit. 回答1: Your tag definition is not correct. You need to use register.simple_tag decorator:

Django template inline jQuery not working

十年热恋 提交于 2020-01-24 10:53:50
问题 Trying to get inline jQuery in my template working so that I can use django url tags in AJAX calls later. But I can't get the javascript to work. In my subpage I extend my index page which has all my javascript and jQuery libraries. {% extends "subpage.django" %} {% block content %} <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script> <script> $("#dialog").hide(); $(".delete").click(function(){ alert("clicked!"); }); </script> {% if

django: calculate percentage based on object count

巧了我就是萌 提交于 2020-01-23 12:53:47
问题 I have the following models: class Question(models.Model): question = models.CharField(max_length=100) class Option(models.Model): question = models.ForeignKey(Question) value = models.CharField(max_length=200) class Answer(models.Model): option = models.ForeignKey(Option) Each Question has Options defined by the User. For Example: Question - What is the best fruit? Options - Apple, Orange, Grapes. Now other user's can Answer the question with their responses restricted to Options . I have

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

。_饼干妹妹 提交于 2020-01-23 07:49:23
问题 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. 回答1: 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

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

孤街醉人 提交于 2020-01-23 07:49:10
问题 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. 回答1: 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

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

寵の児 提交于 2020-01-23 07:49:09
问题 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. 回答1: 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