django-templates

Use Django Template Tags in img src [duplicate]

柔情痞子 提交于 2019-12-11 19:41:34
问题 This question already has answers here : django 1.5 - How to use variables inside static tag (5 answers) Closed 4 years ago . I am trying to use the Django template tags to bring up specific images that correlate with each choice, however it does not seem to work, just return a broken image. Here is my relevant html: <img class="img-responsive" src="{% static "images/risk_graphics/{{ input.choice }}.jpg" %}"/> Thanks for any help. 回答1: Just set a variable on the context containing the path to

How to display model fuction in Django template

丶灬走出姿态 提交于 2019-12-11 19:27:52
问题 What I am trying to do is to get the data from my model to show up a bootstrap modal. What I am doing right now is trying to pass the function data into the view and through the view I am trying to show the with in the modal. The issue I am encountering is: Invalid block tag on line 47: 'show_profile', expected 'empty' or 'endfor'. Did you forget to register or load this tag? Am I doing something wrong when I am trying to pass the data in or is something wrong with my tag or something else?

'str' object has no attribute 'label' when validating

社会主义新天地 提交于 2019-12-11 19:25:32
问题 Okay, this is a weird one, at least to me. I have a form that contains event_date and article_date . I want to confirm that event_date is not bigger than article_date , because that would mean that the event would take place in the future, which is not possible. Now, what I did is this: def clean(self): cleaned_data = self.cleaned_data event_date = cleaned_data.get("event_date") location = cleaned_data.get("location") article_date = cleaned_data.get("article_date") if event_date and location:

use css in django 1.4 development

浪子不回头ぞ 提交于 2019-12-11 19:12:22
问题 I'm looking for a way to use a css file in django. I tried many things and I searched in many forums but I can't find my mistake. This is my code: Directory structure: /projecte manage.py /projecte settings.py url.py wsgi.py /static /css estil.css /templates inici.html /principal models.py views.py forms.py URL.py from django.conf.urls.static import static from django.contrib.staticfiles.urls import staticfiles_urlpatterns urlpatterns = patterns('', url(r'^$','principal.views.inici'), ... )

How to incorporate Reportlab with Django Class Based View?

走远了吗. 提交于 2019-12-11 18:45:39
问题 I am trying to convert my HTML to a PDF. I watched this tutorial, https://www.codingforentrepreneurs.com/blog/html-template-to-pdf-in-django/ and I was able to successfully get the tutorial to work with hardcoded values. The problem is...I can't figure out how to dynamically incorporate my model and it's attributes into this example. Here are the steps I followed... First I installed reportlab into my environment with the following version... pip install --pre xhtml2pdf This worked... Then I

Django how to iterate querysets of two subclasses in template?

此生再无相见时 提交于 2019-12-11 18:29:43
问题 I am using django-model-utils for inheritance Managers. I want to get result of both sub-classes with one dictionary without getting duplicates. models.py class Images(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='images_created', on_delete=models.CASCADE) created = models.DateTimeField(auto_now_add=True, null=True, blank=True) objects = InheritanceManager() class Postimg(Images): user_img= models.ImageField(upload_to='images/%Y/%m/%d', null=True, blank=True)

How To Clear self.add_error in Django if user clicks on browser back button?

十年热恋 提交于 2019-12-11 18:05:35
问题 I have a FORMVIEW where a user selects a value from a dropdown, and if they select the value, and click submit, it performs an HTTPResponseRedirect to a URL and all is well. If they forget to enter a value and click submit, they get an error message telling them to choose a value. I do a clean on the form to figure this out. This all works just fine. The issue is if the user gets an error message, then adds a value and then displays the desired output. If they then click the back button on

How To Narrow Down Django DetailView Export To CSV File

落花浮王杯 提交于 2019-12-11 17:57:27
问题 I am trying to figure out how to do a simple export of data to a CSV file. I found an example that works.... def export_data(request): response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="users.csv"' writer = csv.writer(response) writer.writerow(['username', 'First name', 'Last name', 'Email address']) users = User.objects.all().values_list('name','userid') for user in users: writer.writerow(user) return response The code above works as you

Insert for loop item in django output field

假如想象 提交于 2019-12-11 17:51:02
问题 I have a for loop in my django template: {% for item in data %} {{ item.Load}} {{ item.To }} {{ item.From }} {{ item.Weight }} and I want to parse item.load in this format {{ forminput.field.value|default_if_none:"" }} but when I do this, {{ forminput.field.item.Load|default_if_none:"" }} it doesn't show my field in the django form. When I enter a static value(e.g. 3) in this it appears in the form like this {{ forminput.Load_ID.3|default_if_none:"" }} it shows the 4th object on the page. How

Do I have to re-render my page after updating template data

Deadly 提交于 2019-12-11 17:41:50
问题 First I have searched and seen another answer, but it doesn't address my need. I am trying to POST data using jQuery/AJAX from my HTML to update a list that is also on my HTML. When I first rendered my template, it had two list-group containers of which the left container is pre populated. two containers The choice made user makes on the left container determines the list group data of the right container . I wanted to send back to the backend Python (server) which selection the user made