These are chat archives for django/django

Jul 2017
Anish Shrestha
Jul 03 2017 06:49
stores = InfiniaStore.objects.annotate(s1=TrigramSimilarity('display_name', term),
                                           s2=TrigramSimilarity('city', term),
                                           norm_distance=annotate_distance(lat, lon)/dis_limit)\
        .filter(norm_distance__lte=1).annotate(dumb_rank=F('s1')+F('s2')+(1 - F('norm_distance'))).\
normalizing in the queryset. DONE.
though that's a dumb way. But still.
fixed my last problem.
Abhinandan Panigrahi
Jul 03 2017 06:59
Hi guys, I'm trying to get django to send the JWT in the response header and not the response body ({"token":TOKEN}) as is usual. I'm using django-rest-framework-jwt
Jul 03 2017 08:05
Hey guys, since several days ago I've been experiencing some issues, I get a colossal amount of these error logs Truncated or oversized response headers received from daemon process 'flgn':
Aaron Layfield
Jul 03 2017 08:05
@chrzrdx According to the documentation they expect it in the header, so I would assume it is in the header? How are you sending it in the code? SHow us a handler.
Jul 03 2017 08:07
@DandyDeveloper I did, doesn't help
In fact that's the exact version of mod_wsgi I'm using
Aaron Layfield
Jul 03 2017 08:09
The error itself is cryptic as its only reporting the header being too large. Can you see which header is causing the problem? Excessively large headers generated by Django would suggest a issue in the code somewhere
@axegon Also, as per that article, the update to Apache will only make the message less cryptic. Its being pretty clear that the response header from Django is way too big. The default is 8124 bytes, so you'll need to increase that if the header is correct.
Jul 03 2017 08:13
@DandyDeveloper aiight, I'll try increasing the header-buffer-size, I think I know which header it might be(complex authentication), seems weird however cause this has been up and running for years like that
Aaron Layfield
Jul 03 2017 08:17
Might be worth investigating why its become so much larger then (You never know if someones tampered with something).
Ahmed Kotb
Jul 03 2017 09:01
Hello, I have a question/answer app that is for every combination of answers, I have to render possible results. any ideas how to implement the result calculation
Job Matheka
Jul 03 2017 09:38

[Mon Jul 03 09:06:35.669513 2017] [wsgi:error] [pid 28629:tid 140629543728896] [Errno 2] No such file or directory: '/index.html'
apache2 after deploying a django app on ubuntu ec2 instance.
here is my file contents:

import os
import sys
import site

# Add the sitepackages of the chosen virtualenv to work with

# Add the app's directory to the PYTHONPATH

os.environ['DJANGO_SETTINGS_MODULE'] = 'busara_fitbit.settings'

# Activate your virtual env
activate_env = os.path.expanduser("/home/ubuntu/env/bin/")
execfile(activate_env, dict(__file__=activate_env))

from django.core.wsgi import get_wsgi_application
from dj_static import Cling, MediaCling

application = Cling(MediaCling(get_wsgi_application()))


        WSGIDaemonProcess myapp
        WSGIProcessGroup myapp
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptAlias / /home/ubuntu/my_app/app/
        Alias /static/ /home/ubuntu/myapp/static/
        <Directory /home/ubuntu/myapp>
            Require all granted

what could be the issue?

Aaron Layfield
Jul 03 2017 09:39
Is your site enabled through Apache? Its missing index.html but I can't see you defining this anywhere in your Apache config.
Job Matheka
Jul 03 2017 09:40
Not sure, how do i enable it?
Aaron Layfield
Jul 03 2017 09:49
@jobm a2ensite <<name of site>>
Job Matheka
Jul 03 2017 12:12
@DandyDeveloper Not sure how to do that. But thanks for taking your time.
Aaron Layfield
Jul 03 2017 12:13
If you've configured an Apache site-available configuration file (or conf-available, sorry I use Nginx) you need to enable using the above. However, the error actually says it can't find index.html so where are you referencing index.html?
Shashank Parekh
Jul 03 2017 13:22

While migrating from django 1.9 to django 1.11, getting error.

The file 'css/bootstrap.17dd7c2e.css' could not be found with < object at 0x7fdca5c2ce50> ?
Any idea why?

Using aws cdn for content delivery.
Please any help will be appreciated.
Got stuck with this for almost a day.
And in django 1.11 its a ValueError.
Aaron Layfield
Jul 03 2017 14:49
@sp1rs Have you run collectstatic with
Shashank Parekh
Jul 03 2017 14:50
@DandyDeveloper Yes
Aaron Layfield
Jul 03 2017 14:51
Shashank Parekh
Jul 03 2017 14:51
It is working fine on local env, but in prod env, its throwing error.
Is it related to django 1.11? or is it because of cdn?
Aaron Layfield
Jul 03 2017 17:34
@sp1rs Specifically seems to related to Django. Sorry I went AFK.
Jul 03 2017 17:48

hi, while trying to run some tests, am getting this error

C:\Users\Mlamba\Envs\venv\Scripts\python.exe D:/code/blog/posts/
Traceback (most recent call last):
  File "D:/code/blog/posts/", line 3, in <module>
    from posts import factories
  File "D:\code\blog\posts\", line 9, in <module>
    from . import models
  File "D:\code\blog\posts\", line 5, in <module>
    class Post(models.Model):
  File "D:\code\blog\posts\", line 6, in Post
    author = models.ForeignKey('Author')
  File "C:\Users\Mlamba\Envs\venv\lib\site-packages\django\db\models\fields\", line 846, in __init__
    to, on_delete, from_fields=['self'], to_fields=[to_field], **kwargs)
  File "C:\Users\Mlamba\Envs\venv\lib\site-packages\django\db\models\fields\", line 491, in __init__
    super(ForeignObject, self).__init__(rel=rel, **kwargs)
  File "C:\Users\Mlamba\Envs\venv\lib\site-packages\django\db\models\fields\", line 172, in __init__
    self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "C:\Users\Mlamba\Envs\venv\lib\site-packages\django\conf\", line 56, in __getattr__
  File "C:\Users\Mlamba\Envs\venv\lib\site-packages\django\conf\", line 39, in _setup
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Process finished with exit code 1

Here is my file

WSGI config for blog project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blog.settings")

application = get_wsgi_application()
Shashank Parekh
Jul 03 2017 17:49
@sp1rs Specifically seems to related to Django. Sorry I went AFK.Thanks for the help.
۞ Abdel-Malik ۞ 🇵🇸
Jul 03 2017 19:15
Hi, I'm following the next course on Django and I'm at the party on URLs
I do not understand the part about URLs, why create another URL file? Unfortunately I have an error message here
Kyle Mulka
Jul 03 2017 19:57
I'm getting an internal server error with a fairly standard django setup. It should return a 400 error, but is instead returning a 500 error. django 1.8.18
I'm proxying through nginx to simulate an SSL-terminating load balancer
http {
    server {
        listen 8080;
        location / {
            proxy_pass http://localhost:8000;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Proto https;
curl -X POST --referer 'blah' http://blah:8080 -I
I feel like the combination of the post, invalid referer and the proxy is causing the 500
wondering if there's a simple way to change the django config to make this type of request not cause a 500
Jul 03 2017 20:45

Hey looking for some help getting the following error

Got AttributeError when attempting to get a value for field `workon` on serializer `IssueSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `CommunicationsIssue` instance.
Original exception text was: 'CommunicationsIssue' object has no attribute 'workon'.

I am of course using DRF,
class StoreSerializer(ModelSerializer):

    class Meta:
        model = Store
        fields = ('store_number', 'longitude', 'latitude')
        lookup_field = 'store_number'

class WorkOnSerializer(ModelSerializer):

    class Meta:
        model = WorkOn
        fields = '__all__'
        lookup_field = 'issue_id'

class IssueSerializer(ModelSerializer):
    store = StoreSerializer()
    workon = WorkOnSerializer()

    class Meta:
        model = CommunicationsIssue
        fields = '__all__'
        lookup_field = 'issue_id__store__store_number'
class CommunicationsIssue(models.Model):
    store = models.ForeignKey(Store)
    issue = models.CharField(max_length=5, choices=issues_choices())
    ticket = models.CharField(max_length=100, null=True, blank=True)
    confirmed = models.BooleanField(default=False)
    down_since = models.DateTimeField(null=True, blank=True)
    last_checked = models.DateTimeField(auto_now=True)
    resolved = models.BooleanField(default=False)
    resolved_time = models.DateTimeField(null=True, blank=True)

    def __str__(self):
        return "{} - {} - {}".format(, self.get_issue_display(), self.down_since)

    def total_time_down(self):
        if self.resolved is False:
            return ( - self.down_since).total_seconds()
        return (self.resolved_time - self.down_since).total_seconds()

class WorkOn(models.Model):
    issue_id = models.ForeignKey('CommunicationsIssue')
    work_on_by = models.ForeignKey(User)
    work_on_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return '{0} working on {1}-{2} for store {3} at {4}'.format(
Jul 03 2017 20:54
NVM , i got it :D
Jul 03 2017 21:01
Hello everyone!
I'm trying to render a signup banner only on my demo page
my demo is a very simple function which authenticates a particular user (my demo user) I'm not sure if this is the best approach but for now it just works great
in my template I'm trying something like:
    {% if {{request.user.username}} == 'my-demo-username' %}
    {% endif %}
however it doesn't work. I'm rendering this template without any dict or anything..
I get Could not parse the remainder: '{{request.user.username}}' from '{{request.user.username}}'
Shashank Parekh
Jul 03 2017 21:04
@Cosbgn Can you paste your view code also?
@Cosbgn or try this .. {% if request.user.username == ‘xx %} ..
Note: No {{ }} brackets.
Jul 03 2017 21:06

my whole code is:

def dashboard():
    return render (request, 'app/dashboard.html')

and in my template:

    {% if {{request.user.username}} == %}
    {% endif %}

My username is an email

without the {{}} I get Could not parse the remainder: '' from
I think that adding '' around the email fixed it. Let me check..
    {% if request.user.username == '' %}
    {% endif %}
Jul 03 2017 21:19
Yes, this works great. Thanks @sp1rs