django-templates

Django: Using a variable as the URL namespace?

孤街浪徒 提交于 2019-12-31 04:14:04
问题 I'm trying to create a submenu for a sports site. Each sport would need its own submenu. The problem I'm having is I need the namespace itself to be dynamic in someway. SportListView returns the sport so I can then filter the news articles by the sport. Views: class SportListView(ListView): template_name="sports/sport-home.html" context_object_name='sport_list' def get_context_data(self, **kwargs): context = super(SportListView, self).get_context_data(**kwargs) context['sport_menu'] = get

Django: put offline a post after an event

試著忘記壹切 提交于 2019-12-31 04:13:21
问题 I'm trying to put offline the posts after an event, a definite date. I've developed a simple model for test my aim and inside the model I've put a function( named is_expired ) that, ideally, must define if a post is or not is online. Below there is the model : from django.db import models from django.utils import timezone import datetime class BlogPost(models.Model): CHOICHES = ( ("Unselected", "Unselected"), ("One Month", "One Month"), ("One Year", "One Year"), ) title = models.CharField(

django ValueError: invalid literal for int() with base 10: ''

为君一笑 提交于 2019-12-31 03:54:13
问题 I have an issue with my site, receiving this error pretty often. It's the first time i've run into this and maybe someone can shed some light as to why? Traceback (most recent call last): File "/opt/python2.6/lib/python2.6/site-packages/django/core/handlers/base.py", line 92, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/www/django_test1/fundedbyme/project/views.py", line 194, in browse items = Project.objects.filter(categories__slug=cat_name, status=

Using Django to summarize Report

≡放荡痞女 提交于 2019-12-31 03:12:21
问题 I'm trying to produce a table that will show the total maturity amounts for each financial institution that a plan has. A plan is the term I use for person. So each person can have multiple investments. I'm having trouble creating a table that will do this correctly. Currently I have a report that displays each investment sorted by Maturity Date, i.e. 2011,2012, etc. At the bottom I would like to place this summary table, but my query displays duplicates of each financial institution, due to

Python/Django is importing the wrong module (relative when it should be absolute)

前提是你 提交于 2019-12-31 03:11:53
问题 I'm using Django 1.2 pre-alpha and Python 2.4. Yeah, I know, but I'm stuck with it. We can't upgrade at the moment and I doubt that's the answer anyway. I've got two template tag libraries, foo and bar . However, foo is also the name of a top-level package, and it happens to be the package of bar : foo-1.2.3/ foo/ conf/ settings.py templatetags/ bar.py bar-4.5/ somepackage/ templatetags/ foo.py The tag library bar.py contains a line like this: from foo.conf import settings ...and you would

“Reverse for … not found” - but there is?

帅比萌擦擦* 提交于 2019-12-31 01:49:04
问题 Ok, I've been banging my head against this for 30+ minutes, so here I am on stack overflow. I've got in a template: {% if user.is_authenticated %} <a href="{% url 'admin' %}"> Admin </a> {% endif %} And in urls.py: urlpatterns = [ path('admin', admin.site.urls, name = 'admin'), path('', views.index, name ='index'), ] Yet I still get: NoReverseMatch at / Reverse for 'admin' not found. 'admin' is not a valid view function or pattern name. Why is that? I even tested it out, and replaced admin

Django float format get only digits after floating point

旧街凉风 提交于 2019-12-30 11:34:40
问题 Is there a django template filter to get only digits after the floating point? For example : 2.34 --> 34 2.00 --> 00 1.10 --> 10 I have not found an answer in https://docs.djangoproject.com/en/dev/ref/templates/builtins/. 回答1: Aside from creating your own custom filter, you can solve it using django-mathfilters package: {{ value|mod:1|mul:100|floatformat:"0" }} where: mod is a "modulo" filter provided by mathfilters mul is a "multiplication" filter provided by mathfilters floatformat is a

Django: union of different queryset on the same model

て烟熏妆下的殇ゞ 提交于 2019-12-30 11:18:51
问题 I'm programming a search on a model and I have a problem. My model is almost like: class Serials(models.Model): id = models.AutoField(primary_key=True) code = models.CharField("Code", max_length=50) name = models.CharField("Name", max_length=2000) and I have in the database tuples like these: 1 BOSTON The new Boston 2 NYT New York journal 3 NEWTON The old journal of Mass 4 ANEWVIEW The view of the young people If I search for the string new , what I want to have is: first the names that start

How to use 3rd party app templatetags with Jinja 2?

别来无恙 提交于 2019-12-30 08:15:27
问题 I am trying Jinja2 for my Django website. Now, since Jinja2 is not official Django templating engine and its refusing to recognise / load the template tags I was using prior to Jjinja2. Now, even if there has to be a change in the template tags creation, then how is it possible to reflect across the 3rd party apps? In that case it seems impossible to use Jinja2 since the system has to work as per Jinja2. (I am also using coffin as an adapter for Jinja-Django). 回答1: According to coffin docs

python add a new div every 3rd iteration

穿精又带淫゛_ 提交于 2019-12-30 07:56:10
问题 I have a product list that put 3 products on a row and clears the row and adds another 3, this works fine everywhere but IE6, i know that adding <div> around each group of 3 products will solve this is the template file at the moment {% for product in category.products.all %} <div class="{% cycle 'clear' '' '' %}"> <a href="{% url shop.views.product category.slug product.slug %}"><img src="{{MEDIA_URL}}{{product.mini_thumbnail}}" alt="{{product.name}}" class="thumbnail"/></a> <div class="prod