django-templates

Pass Dynamic Value to Django url built-in

a 夏天 提交于 2020-04-18 04:43:18
问题 Within a view, I am maintaining a dictionary containing some data I would like to display in an <a> in a template with the Django url built-in. my_view.py links = [ { 'name': 'link 1', 'pattern': 'fe:upload' }, { 'name': 'link 2', 'pattern': 'fe:download' } ] It will work hardcoded like this: <a href="{% url 'fe:upload' id %}">up</a> <a href="{% url 'fe:download' id %}">down</a> However I'm struggling to put it into a loop my_template.html <ul> {% for link in links %} <li> <a href='{% url

Django doesn't load css file

跟風遠走 提交于 2020-04-18 03:51:30
问题 I tried to search many posts about this problem and any one those couldn't solve my problem sadly and I couldn't understand on some points.This is the post. Django cannot find static files. Need a second pair of eyes, I'm going crazy I guess this is the most similar case with me and someone gave very nice answer for it, but it couldn't solve my problem :/ This is my file set - beerlog - beerlog - settings.py - ... - posting - urls.py - templates - posting - base.html - index.html - post.html

How to stop __init__ of a class based view executing twice in django?

让人想犯罪 __ 提交于 2020-04-18 03:44:11
问题 I have shuffled the questions and corresponding options in the exam. Once student has wriiten the exam score will be displayed, and I want to show the student their answer sheet in the same way as they have seen while writing the exam with their answers and correct answers. So I decided to use random.seed(). Why init () is executing twice ? [12/Mar/2020 14:08:58] "GET /exam/4/ HTTP/1.1" 200 11103 [12/Mar/2020 14:41:15] "GET / HTTP/1.1" 200 5059 init seed = 13 student now writing the exam with

django form and title property

穿精又带淫゛_ 提交于 2020-04-13 06:15:20
问题 i need to render my forms with the property "title" for jquery validation, how ill render my forms in this way? <input name="name" id="name" title="Please fill Your name!" value="" type="text" /> Thanks guys 回答1: Simplest way is to set this attribute manually and static like this: class MyForm(forms.Form): myfield = forms.CharField(widget=forms.TextInput(attrs={'title':"MYMEGATITLE","id":"MY_ID",'size':'60','maxlength':'70'} )) 来源: https://stackoverflow.com/questions/2884382/django-form-and

django form and title property

孤人 提交于 2020-04-13 06:14:59
问题 i need to render my forms with the property "title" for jquery validation, how ill render my forms in this way? <input name="name" id="name" title="Please fill Your name!" value="" type="text" /> Thanks guys 回答1: Simplest way is to set this attribute manually and static like this: class MyForm(forms.Form): myfield = forms.CharField(widget=forms.TextInput(attrs={'title':"MYMEGATITLE","id":"MY_ID",'size':'60','maxlength':'70'} )) 来源: https://stackoverflow.com/questions/2884382/django-form-and

Django template won't update

家住魔仙堡 提交于 2020-04-10 09:13:11
问题 I have a django base template and I added a few JS libraries, but every time I refresh the page no changes are shown. I have already tried deleting my browser's cache and history and all that. I'm not using django cache anywhere in my code, is it posible that a configuration in settings.py may be causing this behavior? (I've already checked that file and there's nothing related to cache...) I've already restarted django development server and tried, nothing to do there... Is there anything

How to display month name by number?

China☆狼群 提交于 2020-04-08 08:56:55
问题 I have a number represented month and i want to replace it with month name, date filter not working: {{ monthnumber|date:"M" }} I want to place two links - next month and previous month, but i have only number of month. How to do it? 回答1: You'll need a custom template filter to convert the number into a month name. Pretty simple if you use the calendar module from the standard library: import calendar @register.filter def month_name(month_number): return calendar.month_name[month_number]

How to append values in a tabular format from JSON in Django Template?

此生再无相见时 提交于 2020-03-25 13:48:44
问题 I am making a small web application that allow user to perform OCR on the selected image and provides the JSON output in a tabular Format like this. JSON DATA : { "data": { "test_1": { "test_name": "FASTING SUGAR", "results": "121.00", "units": "mg%", "low_range": 70.0, "high_range": 110.0 } } } What I'm facing now is when I'm selected new image to add values in the table, it overrides the values instead of appending. And what I want is to append new value in the table by choosing another

Django cannot create or render comments

ε祈祈猫儿з 提交于 2020-03-24 00:16:46
问题 Hi have this structure to handle users posts and comments my post model is from django.db import models from django.contrib.auth.models import User class Post(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, default=0) profile = models.ForeignKey('users.Profiles', on_delete=models.CASCADE, null=True, default=1, blank=True) title = models.CharField(max_length=100, blank=True, null=True) desc = models.CharField(max_length=1000, blank=True, null=True) photo = models

Django templates extending and CSS

本秂侑毒 提交于 2020-03-18 04:14:45
问题 I have such base template: <head> <title>{% block title %}{% endblock %}</title> <link rel="stylesheet" href="/static/style.css"/> And this text in logs when I refresh the page: [01/Dec/2011 18:22:00] "GET /search/ HTTP/1.1" 200 2760 [01/Dec/2011 18:22:00] "GET /static/style.css HTTP/1.1" 200 54 So, it means that CSS loads from server correctly. But it doesn't work! If I include this CSS as text directly into the base template, it works properly. The static files configuration is OK. 回答1: Are