Category "django"

django: return string from view

I know this is a simple question, sorry. I just want to return a simple string, no templates. I have my view: def myview(request): return "return this st

How To Open and Read a File of Type FileField in Django?

I am trying to open a file that would be uploaded through the django FileField attribute. I also want to read the contents of the file and output it. But when I

Python Django 1.6 execute function for every request before getting to view

I'm writing some API functionality for my project using Python 3.4 and Django 1.6. All functionality works fine, but I want execute one function for all that k

Pyinstaller and Django Rest

I am trying to use Pyinstaller with django rest, it generates the .exe well but there is an error at the moment of executing the .exe, the error is this Module

Django ORM returns non-iterable object

The model is class WeeklyStrMst(BaseModel): StoreId = models.AutoField(primary_key=True) TDLinx_No = models.IntegerField(blank=True, null=True, default=

Django Rest Framework - prevent access to API?

I'm using Django Rest Framework and Token Authentication. Everything works great so far. http://www.django-rest-framework.org/api-guide/authentication#tokenaut

psycopg2.errors.UndefinedTable: relation "libman_classbooks" does not exist

I had mistakenly deleted my migration folders for all my apps in my project. I therefore had to redo makemigrations and migrate for each of those apps. When th

Channels websocket AsyncJsonWebsocketConsumer disconnect not reached

I have the following consumer: class ChatConsumer(AsyncJsonWebsocketConsumer): pusher = None async def connect(self): print(self.scope)

AWS beanstalk + Django: 502 Bad Gateway - ModuleNotFoundError: No module named 'application'

I'm trying to deploy Django project to Elastic Beanstalk. I'm following their guide: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python

How does companies make staff users?

Apologies since this might not be the best way to word the question nor is this a coding question per say. I get the general process of creating a staff user wi

Static File Hosting, WhiteNoise not Updating - Django

I have a Django website in production and a while back I successfully hosted my static files using Whitenoise so I could use them in production. Now a few month

Pass extra arguments to Serializer Class in Django Rest Framework

I want to pass some arguments to DRF Serializer class from Viewset, so for I have tried this: class OneZeroSerializer(rest_serializer.ModelSerializer): de

How to use swagger_auto_schema in a class based view with no serializer_class and how to add custom authentication permission to it?

I have a class based view as: class ClassBasedView(GenericAPIView): @swagger_auto_schema(responses={201: 'Created'}) @authorize(myCustomPermission)

Failed to load resource: the server responded with a status of 502 (Bad Gateway)

How can you solve a 502 error? I believe whats causing the 502 error is a nested loop that contains heavy calculations. It would take up to 2 minutes for it t

Add extra context to admin index page

In my admin.py of my admin dashboard app I added this following code: class MyAdminSite(admin.AdminSite): def index(self, request, extra_context=None):

In Django, how can we stop losing the details filled in the form, if it fails validation?

I am using the UserCreationForm for user registration in my Django web app. When the user fills in the detail (username, password, confirm_password) and submits

404 (Not Found) for CSS files

I am running a django app and I want to import a third-party stylesheet from my node_modules. But my django app is looking in the wrong directory and throws a 4

CSRF validation does not work on Django using HTTPS

I am developing an application which the frontend is an AngularJS API that makes requests to the backend API developed in Django Rest Framework. The frontend

How to use Faker from Factory_boy

Factory_boy uses fake-factory (Faker) to generate random values, I would like to generate some random values in my Django tests using Faker directly. Factory_bo

Error while opening Django admin: "Error at /admin/ Incorrect padding"

I was making a web app using Django. I was using Django 3.0.7 for the sake. Then I upgraded to Django 3.1.1. When I reinstalled Django 3.0.7 I am unable to open