django-templates

Django ajax error

白昼怎懂夜的黑 提交于 2019-12-11 11:16:04
问题 I am getting an error while using AJAX to populate a table inside my django template. I am not sure what the error is, please help me in resolving this issue. I have shared all the important files, if I remove ajax and redirect the url to the destination URL then the code works fine, but somehow the ajax implementation is throwing an error. Exception happened during processing of request from ('127.0.0.1', 64879) Traceback (most recent call last): File "c:\Python27\Lib\SocketServer.py", line

django using MEDIA URL in a template

爷,独闯天下 提交于 2019-12-11 11:14:17
问题 i'm trying to access files that were uploaded by users. i have the following settings: MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'project/media/') MEDIA_URL = '/project/media/' and the file are: path = models.FileField(upload_to="myApp") image = models.ImageField(upload_to="myApp/logos", null=True, blank=True) in the template i try to acces it in the following way: {{MEDIA_URL}}{{file.path}} but it doesn't work.. what am i doing wrong? 回答1: file.path returns an object representing the file,

django.core.context_processors.request Not working

跟風遠走 提交于 2019-12-11 11:09:02
问题 I have this in my setting.py : TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.request', 'django.core.context_processors.static', 'django.contrib.auth.context_processors.auth', ) Whenever I try to access the request in a template (for example {{ request.user.get_profile.custom_username }} ) I get no result. I think the request is not added to the template, because if i force the request in to the Context (in the view), I can access it: ctx = {} #ctx['request'] = request return

How to give the path for template directory

允我心安 提交于 2019-12-11 10:13:41
问题 My templates are not recognized and I'm getting the following error. os.path.dirname(__file__)+'\\template' NameError: name 'os' is not defined The code which I have used in settings is: os.path.dirname(__file__)+'\\template' what should I do now. 回答1: os module is missing You have used it without importing Add this in your settings.py import os TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),) and place all your templates under templates folder in your project and you

No module named 'django.templates'

老子叫甜甜 提交于 2019-12-11 10:09:35
问题 I am using python 3.4, django 1.8. I am using pycharm for developing. While running the program ,I am getting 'No module named 'django.templates'' error. settings.py """ Django settings for dj project. Generated by 'django-admin startproject' using Django 1.8.1. For more information on this file, see https://docs.djangoproject.com/en/1.8/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.8/ref/settings/ """ # Build paths inside the project

Django and Chartjs template conflict

六眼飞鱼酱① 提交于 2019-12-11 10:04:51
问题 I'm trying to set the tooltipTemplate property of a line chart to <%if (label){%><%=label%>: <%}%><%= value %> , but I'm using Django on the backend. So, if I try to use the literal value of tooltipTemplate , Django will interpret the {% and %} as part of its template language. How can I avoid this? tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>" 回答1: You can use the verbatim tag. {% verbatim %} tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>" {% endverbatim %}

Django templating language syntax for navbar notifications

五迷三道 提交于 2019-12-11 09:55:19
问题 I am trying to use the Django templating language in my Django Channels 2.1.2 project to render out any unread chat messages in a Facebook-style notification popup. The list of unread chatmessages (in their respective threads ) are not displaying because I am having trouble with the correct syntax. This is how the front end looks. When you click the message icon, the notification disappears. I have a Notification model class Notification(models.Model): notification_user = models.ForeignKey

“View on site” button is linked to an unwanted page

回眸只為那壹抹淺笑 提交于 2019-12-11 09:52:54
问题 Why "view on site" linked to an unwanted page? Can I disable it? 回答1: View on site determines the URL to link to by checking the Sites app and adding the model's get_absolute_url() method on the end of it. 回答2: See the django-docs You can overwrite the admin-templates or see here, how to use it 回答3: the easiest and cleanest way is to set admin.site.site_url = None in your root urls.py it works since django 1.8, here is the documentation 回答4: sudo vi /usr/local/lib/python2.6/dist-packages

Django templates whitespaces ans empty characters in for loop

邮差的信 提交于 2019-12-11 09:48:40
问题 I have a piece of django template responsible for listing some labels if there are in passed list sources : <div id="selected-sources" style="min-height:150px; max-height:500px"> {% for source in sources %} <span id='{{source.0}}' class='tag_with_remove'> <i class='icon-remove'></i> <span class='label'>source: {{source.1}}</span> </span> {% endfor %} </div> What results in: <div id="selected-sources" style="min-height:150px; max-height:500px"> </div> when sources is empty. But I would like it

django regroup and than dictsort by list length

不想你离开。 提交于 2019-12-11 09:17:05
问题 I need to regroup a list, than to show the results ordered by the number of items per result's list. something like this: {% regroup car_models by make as car_models_by_make %} {% for make in car_models_by_make|dictsort:"???" --> the problem %} {{ make.grouper }} ({{ make.list|length }}) <br> {% endfor %} so if the data is: [ ('panda','fiat'), ('500','fiat'), ('focus','ford') ] the result should be: fiat 2 ford 1 I tried: dictsort:"make.list.count","make.list.length","make.list|length" ..