Questions tagged [django]

Django is an open-source server-side web application framework written in Python. It is designed to reduce the effort required to create complex data-driven websites and web applications, with a special focus on less code, no-redundancy and being more explicit than implicit.

django
106,158 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
22 votes
1 answer
2k views

Graphene-python performance issues for large data sets

Currently using graphene-python with graphene-django (and graphene-django-optimizer). After receiving a GraphQL query, the database query is successfully completed in a fraction of a second; however, ...
techknowfile's user avatar
15 votes
0 answers
738 views

Django channels with Spring Boot Websockets (StompSession) do not work

Hey there we want to use Django just to execute python code and use channels for the results. Implemented everything the websockets are not working as they should. If I try to send something from our ...
CptDayDreamer's user avatar
14 votes
1 answer
2k views

Graphene-Django and many to many relationship lookup

I have two Django models - Teacher and Student and have a many-to-many relationship. Teachers can have multiple students and students can have multiple teachers. There is 'through' model called '...
dotslash227's user avatar
14 votes
1 answer
3k views

How to create custom filter using graphene-django and Relay that use multiple fields of different types?

Problem Hello, I'm using Graphene Django and Graphene Relay with Python 3.7. I'm trying to make a custom filter for the requests in GraphQL using Django filters. My table looks like this: | id(...
user avatar
14 votes
1 answer
3k views

Correctly Scraping and Displaying Japanese Characters using Python Django BeautifulSoup and Curl

I'm trying to scrape a page in japanese using python, curl, and BeautifulSoup. I then save the text to a MySQL database that's using utf-8 encoding, and display the resulting data using Django. Here ...
Ryan Rogers's user avatar
13 votes
1 answer
14k views

Supervisor FATAl Exited too quickly (process log may have details(About inet_http_server and unix_http_server)

I wrote a Django project and I use supervisor with gunicorn /etc/supervisor/conf.d/weather.conf [group:weather_station] programs=site [program:site] directory=$PROJECT command=/home/nhcc/.local/...
Jonathan Cheng's user avatar
13 votes
1 answer
4k views

How to profile Django on Gunicorn in production

I have a memory leak that is hard to reproduce in testing environment. So I'd like to profile my production server for a limited time period to get an overview about which objects take up most memory. ...
Wolkenarchitekt's user avatar
13 votes
1 answer
2k views

How can I use `django-rest-knox` with `django-rest-auth`?

I'd like to use django-rest-auth to easily make use of the registration and social auth features of django-allauth in my API. I'd also like to use django-rest-knox, as it provides a token per device, ...
StringsOnFire's user avatar
12 votes
0 answers
3k views

How to configure Celery to run as systemd service with a Django application served by Gunicorn?

I followed the official Celery documentation regarding how to configure Celery to work with Django (python 3) and RabbitMQ. I already have a systemd service to start my Django Application using ...
donmelchior's user avatar
12 votes
0 answers
3k views

Gunicorn spiking CPU to 100% on certain pages...killing performance

I have a Django app that is being served through Nginx / Gunicorn. When loading certain pages, Gunicorn is spiking in CPU usage to 100% and totally killing performance, causing the page to take 10 ...
demluckycharms's user avatar
12 votes
1 answer
2k views

'TopLevelDocumentMetaclass' object is not iterable

I am very new to django world and I try to do some example to use it with mongodb. To connect to mongo I am using mongoengine 0.9.0. I am also using virtualenv. At the moment I have pretty basic ...
Raúl's user avatar
  • 121
12 votes
2 answers
4k views

Django: Annotate based on an annotation

Let's say I'm using Django to manage a database about athletes: class Player(models.Model): name = models.CharField() weight = models.DecimalField() team = models.ForeignKey('Team') ...
8one6's user avatar
  • 13.4k
12 votes
1 answer
2k views

Django + Psycopg2: InterfaceError: only protocol 3 supported

When loading pages in my Django + Postgresql setup I occasionally get this error but not all the time: psycopg2 in connect InterfaceError: only protocol 3 supported psycopg2/__init__.py ? in connect ...
samgreeneggsham's user avatar
12 votes
2 answers
2k views

Django 1.4: How to ignore fields, models in loaddata

We have a compressed dumpdata of 15MB upload extracting goes to 100MB. It has few models & fields that are not used in current tables. Specifically, there are few contenttypes models which can be ...
Iamcool's user avatar
  • 1,415
11 votes
1 answer
5k views

django.db.utils.InterfaceError: connection already closed

Stack: Ubuntu (20.04 LTS) Nginx Postgresql (v13.3) An AWS load balancer sends traffic to the Ubuntu instance(k8s cluster), which is handled by Nginx, which forwards on to Django (4.0.3) running in ...
Michele Matera's user avatar
11 votes
1 answer
2k views

Can't push local Postgre database to Heroku

i have a problem getting my local database into Heroku.I'm currently working on building a Django web application and I tried to learn about getting local database to Heroku .I was trying to push my ...
ChangNoi997's user avatar
11 votes
1 answer
977 views

mypy django rest framework - Unsupported left operand type when multiple permission classes are used

I am integrating mypy on a existing codebase(using django, drf frameworks). Sample code in view.py: from rest_framework.permissions import IsAdminUser, IsAuthenticatedOrReadOnly @api_view() @...
partha biswas's user avatar
11 votes
3 answers
2k views

Using join of temporary table as an alternative of `IN` in Django

In Django it's common to do the following MyModel.objects.filter(id__in=[huge array]) However it's not very efficient as described in the following answer here: https://dba.stackexchange.com/...
Jonathan's user avatar
  • 8,652
11 votes
0 answers
788 views

Django Channels deny websocket connection with a custom code

So I need to deny a websocket connection with a specific code so the client can handle the rejection properly. Currently when you reject a connection with message.reply_channel({'accept':False}) the ...
MCBama's user avatar
  • 1,460
11 votes
2 answers
4k views

Where to put service worker and manifest in a django project?

I am planning to convert a django project to Progressive Web App. I am not being able to figure out where to put the service_worker.js and manifest.json files in my django project. I've tried the ...
Outsider's user avatar
  • 1,206
11 votes
0 answers
1k views

websocket-client: socket.error: [Errno 104] Connection reset by peer

I am using Django channels to build an realtime chat application. I have installed websocket-client and when I try to connect using ws.connect(), it throws error 104. connection reset by peer. It ...
Streetway Fun's user avatar
11 votes
2 answers
3k views

Django: app level variables

I've created a Django-rest-framework app. It exposes some API which does some get/set operations in the MySQL DB. I have a requirement of making an HTTP request to another server and piggyback this ...
Pankaj Singhal's user avatar
11 votes
1 answer
1k views

Pycharm not showing all files from django external library

In pycharm under external libraries I'm not able to see all files (e.g all templates are missing). The external librarys are coming from a remote server (docker). On the server itself, I'm able to ...
xhallix's user avatar
  • 2,979
11 votes
1 answer
1k views

Django/djcelery 1.8.2 AppRegistryNotReady: Translation infrastructure cannot be initialized

I am getting the following error: File "/Library/Python/2.7/site-packages/Django-1.8.2-py2.7.egg/django/utils/translation/trans_real.py", line 164, in _add_installed_apps_translations "The ...
Manas's user avatar
  • 399
11 votes
0 answers
911 views

.egg dirs in site-packages when installing python packages?

So I decided to install python packages (technically Django apps) directly from the downloaded tar file, by extracting it and using the following command: python setup.py install However, inside my ...
GoogleDroid's user avatar
11 votes
5 answers
3k views

How can I use prefetch_related in self related model

I have Menu model which has ForeignKey named parent related with itself. If parent is None it means this menu is parent menu if it shows another Menu object it means it is submenu for its parent(many-...
Selim Yılmaz's user avatar
10 votes
3 answers
5k views

How to validate AzureAD accessToken in the backend API

I just wanted to know how can we validate the azure ad access token in a backend API in my case i.e. Django rest framework. Consider that I have a single page app or a native app and a backend API (...
Aashay Amballi's user avatar
10 votes
0 answers
831 views

Handling session-based authentication between Node.js and Django

This may edge upon a "best practice" type of question, but I'd like to explain my approach, list out my hypotheses and get constructive feedback. Currently, my setup consists of two servers; ...
Raghav Kukreti's user avatar
10 votes
0 answers
609 views

How do I query Wagtail tags without it creating hundreds of queries, n+1 problem?

I have a handful of entries that each has dozens of "tags" when I try to fetch that data it causes hundreds of queries. While using prefetching works on all of my other models and links, it does not ...
redhaushq's user avatar
  • 155
10 votes
0 answers
1k views

How to use django channels to stream a script output in real-time?

I am using django to run a python script. Ideally, I would like to redirect the shell output to a webpage and I am using django-channels to this aim. I am trying to call a view that runs the script ...
Francesco1093's user avatar
10 votes
1 answer
3k views

Testing Celery Beat

i work on a celery beat task within a django project which creates Database entries periodically. I know so beacuse when i set the task up like this : celery.py: from __future__ import ...
Chgad's user avatar
  • 860
10 votes
0 answers
1k views

to_python() and from_db_value() methods overlapping in function?

I've been looking at this code example from the docs: import re from django.core.exceptions import ValidationError from django.db import models from django.utils.translation import gettext_lazy as _ ...
Sahand's user avatar
  • 8,248
10 votes
2 answers
7k views

No module named django error when running any manage.py command in docker with docker-compose

I'm getting ImportError: No module named django when trying to up my containers running docker-compose up. Here's my scenario: Dockerfile FROM python:2.7 ENV PYTHONUNBUFFERED 1 RUN mkdir /code ...
Igor Belo's user avatar
  • 738
10 votes
1 answer
567 views

Resolving variables are incompatible in the equal to operator error in SQL

I am getting the following error in django model.objects.get_or_create. SQLServer [FreeTDS][SQL Server]The data types nvarchar(max) and ntext are incompatible in the equal to operator. The column ...
softwarematter's user avatar
10 votes
3 answers
4k views

Auto increment django model field per user

I have this model: class Invoice(models.Model): owner = models.ForeignKey(settings.AUTH_USER_MODEL) data = models.TextField(default=None, blank=True, null=True) number = models....
caruccio's user avatar
  • 305
10 votes
1 answer
959 views

Django-paypal: IPN requests with Invalid Postback

I am building an e-commerce site using django-paypal to accept Paypal payments. 95% of the time, everything works flawlessly, users are able to pay, sandbox or not, and receive what they purchased. ...
Cojo's user avatar
  • 101
10 votes
1 answer
634 views

Automatically generate forms using angularjs and django rest framework

I've noticed, that Django REST framework provides metadata for API endpoint http://www.django-rest-framework.org/api-guide/metadata/ Is there common way to generate forms in angularjs without writing ...
Nikolai Golub's user avatar
10 votes
1 answer
12k views

Why does my program hang after urllib3 logs Starting new HTTPS connection?

I am trying to diagnose an issue where some of my celery worker processes appear to hang for several minutes. I have many tasks that make several IO calls (usually to third party APIs). In any given ...
Scott Coates's user avatar
  • 2,502
10 votes
1 answer
4k views

Where shall I put 'initialization code' in a Django application?

I want some code in my Django app to be executed only once when server is started, not per request. Specifically, I want to load some database tables into memory. These tables contain some 'metadata' ...
NeoWang's user avatar
  • 18k
10 votes
2 answers
4k views

How to modify Browsable API form

Currently, I am creating a UserRegistration view, which should display form with password/confirm password fields. The problem is that the Browsable API displays only fields which occur in the model's ...
Martin's user avatar
  • 1,078
10 votes
1 answer
2k views

Graphene: "Expected a value of type XXX but received: ..."

I'm using graphene-django to build my API. I have a DjangoObjectType named StoreType which represents the model Store. This model has a MultiSelectField named opening_days that indicates what days in ...
martin's user avatar
  • 887
10 votes
4 answers
6k views

Django ModelForm not calling clean

I am performing a basic Django ModelForm create/validate/save operation. My custom clean methods are not being called when is_valid() is being called when running the code under the Eclipse debugger ...
Michael Bartz's user avatar
10 votes
3 answers
2k views

How to integrate multiple image uploading with UPLOADIFY in django administration?

I met the django-uploadify (multiple file uploading) application, but the only template-use is described in wiki of the project. I need to integrate it with django admin. Any ideas?
megido's user avatar
  • 4,225
9 votes
0 answers
3k views

django channels Application instance took too long to shut down and was killed

I have a web server uploaded on a server that receives messages from a Windows app and sends them to a front end in the browser Its late there is a slight delay in receiving and sending and when I ...
Elabbasy00's user avatar
9 votes
1 answer
1k views

Django 3.2 update AutoField to BigAutoField backward compatibility with foreign key relations

I'm running into a problem after updating my project from Django 2.2 to Django 3.2. In Django 2.2 primary keys are created using AutoField meaning in MySql they are considered int(11) and all foreign ...
Maya's user avatar
  • 91
9 votes
0 answers
4k views

How to configure Microsoft Pylance to not use stub files (.pyi) for django?

I am doing Django development using visual studio code on mac os with microsoft's pylance extension installed. Following is the version specification of my eco system : OS -> MacOS Mojave django -&...
Utsav Chokshi's user avatar
9 votes
0 answers
2k views

When is it required to use `schema_editor.connection.alias` in a django `migrations.RunPython` method?

When is it required to use schema_editor.connection.alias in a migrations.RunPython method and why? When using RunPython in a data migration, django advises that you should use schema_editor....
43Tesseracts's user avatar
  • 4,777
9 votes
0 answers
743 views

How can I log information about a GraphQL request in Graphene Django?

Currently, Django logs: [16/Dec/2019 13:29:16] "POST /graphql HTTP/1.1" 200 1735 for any incoming graphql request. I'd like to be able to log more information about the incoming request (which queries,...
Octodone's user avatar
  • 555
9 votes
0 answers
1k views

Django / Mypy: Incompatible type on for models

I'm working on a Django project and I'm using mypy for type checking. To enable type checking for django I'm using the django-stubs package. This works great, but I've now run into a situation where ...
Jasper's user avatar
  • 2,211
9 votes
1 answer
2k views

kombu utils objects py line 42 in __ get __ return obj __ dict __[ self __ name __] keyerror data

settings.py CELERY_BROKER_URL = 'redis://localhost:6379' CELERY_RESULT_BACKEND = 'redis://localhost:6379' CELERY_ACCEPT_CONTENT = ['application/json'] CELERY_RESULT_SERIALIZER = 'json' ...
Pallavi Singh's user avatar

1
2 3 4 5
2124