django-templates

Django Template not loading

折月煮酒 提交于 2019-12-25 14:08:37
问题 I have a project named 'src' and app named 'app' and i have a template folder inside my app. And inside my template folder i have another folder named pages and my html pages(base.html and view.html) are resides there. My view.py is below from django.shortcuts import render from django.utils import timezone # Create your views here. def home(request): return render(request, "pages/base.html", {}) and urls.py from django.conf import settings from django.conf.urls import include, url from

Delayed display of message from within an inclusion tag

妖精的绣舞 提交于 2019-12-25 09:35:04
问题 The following problem is occurring in a large django project. I've been able to replicate the issue in a small mock-up project (code below). I am trying to use the django messaging framework within an inclusion tag to display a message when a POST'ed form returns is_valid(). This approach has also been used in an another answer here (see 'final update' section). The problem is that the message is not immediately displayed when the page is rendered after the POST. Instead the message appears

CSS works only in one of three templates when extended from the same template

会有一股神秘感。 提交于 2019-12-25 09:29:42
问题 Okay I've got my base template and I extended it in my three other templates and it only works in one of them. I find this really strange. I'm not sure what code would relevant here so please comment what code I should post. base: <link rel="stylesheet" type="text/css" href="static/default.css" media="screen"/> <title>{% block title %}Marijus Merkevicius{% endblock %}</title> <div class="holder">{% block content %}{% endblock %} index(css works for this template): {% extends "base.html" %} {%

How to do a proper groupby query in django

馋奶兔 提交于 2019-12-25 08:48:51
问题 I have a table that holds multiple tracking id's in it. What I'm trying to do is group all tracking id's and get a count for them. This is what the SQL query would look like: SELECT tracking_id, COUNT( * ) FROM tracking GROUP BY tracking_id I think I've found the correct method of doing this in django however I'm missing something and am currently getting the error Exception Value: 'dict' object has no attribute 'tracking_id' Here's what my view looks like: def stats(request): users =

can't make if condition with django variable and javascript variable

让人想犯罪 __ 提交于 2019-12-25 08:37:54
问题 i variable type table in javascript , and i need to make a test with if condition between this variable and a variable from django database but it' doesn't work. the example : var test_date = "2017-06-23"; var locations = [ {% for v in vs %} {% if v.date == test_date %} ['okok',{{ v.latitude }},{{ v.longitude}}], {% endif %} {% endfor%} ] the first example doesn't work and i don't know why. other example : var test_date = "2017-06-23"; var locations = [ {% for v in vs %} {% if v.date == "2017

Django template - reading objects through inclusion tag

六月ゝ 毕业季﹏ 提交于 2019-12-25 08:18:20
问题 Continuing from here, I'm trying to create a global nav using values in a model for the link in the nav. I've been pointed in the right direction with inclusion tags, but I'm still not able to work with the objects my inclusion tag returns...I just get blank. I have a simple model called Division: class Division(models.Model): DivisionAbbrev = models.CharField(max_length=20) I have included the template navigation.html in base.html . I am trying to use navigation.html to show the different

Django url tag adds filepath

混江龙づ霸主 提交于 2019-12-25 07:53:44
问题 In urls.py, I defined as, url(r'^'+settings.URL_PREFIX+r'$', 'myapp.project.views.index', name="homepage"), in settings.py, I defined URL_PREFIX as, URL_PREFIX = 'myapp/' and in template, I used url tag in an anchor as, {% url homepage %} Link becomes: http://localhost/home/muluturk/web/myapp/myapp/ instead of http://localhost/myapp/. It adds /home/muluturk/web/myapp/ whis is the directory of project. How can I fix this? 回答1: Problem solved. It caused by apache config file: PythonOption

Django: Check multiple choices with not fixed choices

笑着哭i 提交于 2019-12-25 07:35:39
问题 I am new to Django, and I am trying to create a multiple selection with checkboxes. The problem is that all of the examples that I found have fixed choices that are specified in the form, and I don't need that. More concretely, let this be a model for a simple car dealership app: class CarBrand(models.Model): name = model.CharField() class CarModel(models.Model): name = model.CharField() brand = model.ForeignKey(CarBrand) My goal is when I enter the page for Audi, I get options A3, A4, A5,

How to transfer edit method of an ID to a button/links in Django?

可紊 提交于 2019-12-25 07:35:30
问题 This is the code in my ulrs.py url(r'^viewguides/detail/(?P<id>\d+)/edit/$', views.post_update, name='update'), Now I want to make it look like this: <a href="/detail/(?P<id>\d+)/edit" class="btn btn-default btn-lg" style="background-color: transparent;"><font color="Orange"> EDIT </font></a><hr> So that I can edit the certain ID that I want to. But it gives me an error. How do you do it? or is there any other way? I'm new to Django. 回答1: I just asked my colleagues who have some experience in

getting django Url template tag to return something useful:throws reverse error

╄→гoц情女王★ 提交于 2019-12-25 06:08:22
问题 trying to use the Django {%url %} template tag and keep failing. the view is defined in sitename/transfers/views.py (where transfers is the django app name): def description_ListView(requesst,**kwargs): template_name = 'transfers/description.html' o = get_list_or_404(Transfer, description =kwargs['description']) #print ('o:',o) context_object_name = "transfer_name_list" return render_to_response(template_name,{context_object_name:o,'description':kwargs['description']}) (yes, I DO know that