django-templates

Can't change Django admin template

好久不见. 提交于 2020-01-04 13:47:01
问题 just started an official Django tutorial and already ran into a problem, can't change page name in admin panel. I'm trying to replace a default Django administration with something custom in the base_site.html as suggested in the tutorial (a file which I copied from the django source directory into my app, tried to move it in/out polls directory etc.), I have added in settings TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')] , and in installed apps also 'polls', but nothing changes. Any

Displaying reverse many-to-many in Django Templates

给你一囗甜甜゛ 提交于 2020-01-04 13:42:48
问题 I'm in the midst of creating an alarm/notification system for a small Sales CRM app. I have a Lead_Contact model that is used to store a client's name, address, etc. as well as a Contact_Notifier models that is being used to keep track of when a client was first contacted, the last contact, and when we are going to next contact them. For reference, here is the relevant snippets of the models: class Lead_Contact(models.Model): first_contacted = models.ManyToManyField('Contact_Notifier',

Using Django template inheritance with ngroute - where does `<div ng-view>` go if I want to override blocks outside of `<div ng-view>`?

孤街醉人 提交于 2020-01-04 06:55:26
问题 This is my base.html : <!DOCTYPE html> <html{% block html %}{% endblock%}> {% load static from staticfiles %} <head> <meta charset="utf-8"> <title>{% block title %}Base{% endblock %}</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="{% static 'js/jquery-1.11.3.min.js' %}"></script> <script src="{% static 'js/angular.js' %}"></script> <script src="{% static 'js/angular-route.js' %}"></script> <base href="/"> {% block head %}{% endblock %} </head>

Performance hits from loading Django static tag multiple times

泄露秘密 提交于 2020-01-04 06:07:34
问题 Unless I am doing things wrong, it seems like if you have nested templates (i.e., {% include %} a template within a template), you will sometimes need to call {% load static %} in multiple "layers" of the nest. For example, say I have templateA.html : {% load static %} <a href={% static "some/path" %}>Some Link</a> {% include 'templateB.html' %} And then in `templateB.html, I have: {% load static %} <a href={% static "some/other/path" %}>Some Other Link</a> As far as I can tell from testing,

How can I get a Django Template to render itself within a Mako Template?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 05:30:11
问题 We made the decision quite awhile ago to use Mako Templates in our Django project. We're also supporting Django Templates, since a lot of reusable apps (obviously) assume that Django Templating is available. I've found it possible to render Django Templates from Mako, but I haven't been able to find a way to make it work the other way around. I've just added django-articles to our list of apps, and it uses Django Templating. It assumes that the base.html file is an overriden Django Template.

Django. Apply function to queryset

眉间皱痕 提交于 2020-01-04 05:17:43
问题 I have a queryset and I want to apply function (port_to_app) to its field (dst_port). And then access it from template. How do I do that? I've read about filters and tags, but can't understand the way they work. models.py class FlowQuerySets(models.QuerySet): def top_app(self): return self.values('dst_port')\ .annotate(traffic=Sum('bytes')).order_by('-traffic')[:10] class Flow(models.Model): id = models.BigIntegerField(primary_key = True) ip_src = models.CharField(max_length=15) ip_dst =

How to read the json file of a dynamical way in relation to their size structure

烈酒焚心 提交于 2020-01-04 02:15:15
问题 I have the following JSON file named ProcessedMetrics.json which is necessary read for send their values to some template: { "paciente": { "id": 1234, "nombre": "Pablo Andrés Agudelo Marenco", "sesion": { "id": 12345, "juego": [ { "nombre": "bonzo", "nivel": [ { "id": 1234, "nombre": "caida libre", "segmento": [ { "id": 12345, "nombre": "Hombro", "movimiento": [ { "id": 1234, "nombre": "flexion", "metricas": [ { "min": 12, "max": 34, "media": 23, "moda": 20 } ] } ] } ], "___léeme___": "El

Django use value of template variable as part of another variable name

馋奶兔 提交于 2020-01-04 01:57:06
问题 I currently have this for loop inside my template: {% for i in 1234|make_list %} I would like to obtain something like this inside loop: {{ form.answer_{{ i }} }} I am aware that the above line is not valid (it raises TemplateSyntaxError), but I would like to know if there is any way to use the value of i as part my other variable name. 回答1: First, you would need a custom template filter to mimic getattr() functionality, see: Performing a getattr() style lookup in a django template Then, you

Assign multiple variables in a with statement after returning multiple values from a templatetag

泪湿孤枕 提交于 2020-01-03 20:46:11
问题 Is there a way to assign multiple variables in a with statement in a django template. I'd like to assign multiple variables in a with statement after returning multiple values from a templatetag My use case is this: {% with a,b,c=object|get_abc %} {{a}} {{b}} {{c}} {% endwith %} 回答1: I don't think it's possible without a custom templatetag. However if your method returns always the same length you can do it more compact like this: {% with a=var.0 b=var.1 c=var.2 %} ... {% endwith %} 回答2: I'm

return response in django rest-framework

会有一股神秘感。 提交于 2020-01-03 14:01:11
问题 I am writing an app in django rest-framework: My views.py: class tagList(generics.ListCreateAPIView,APIView): model = tags serializer_class = getAllTagsDetailSerializer def get_queryset(self): print "q1" print self.request.QUERY_PARAMS.get('tag', None) print self.request.user print "q1" if tags.objects.filter(tag='burger')!= None: return tags.objects.filter(tag='burger') else: content = {'please move along': 'nothing to see here'} return Response(content, status=status.HTTP_404_NOT_FOUND) I