uWSGI

Summary Python server used for serving Django web requests at ICTC Solution Delivery Commands Restart service uwsgi-emperor status service uwsgi-emperor restart Installation Emperor - name: Install uWSGI emperor apt: name=uwsgi-emperor state=present - name: Configure uWSGI emperor template: src: emperor.ini.j2 dest: /etc/uwsgi-emperor/emperor.ini owner: root group: root mode: 0644 notify: Restart uWSGI Emperor - name: Create log directory file: path: /var/log/uwsgi/vassals state: directory owner: root group: root notify: Restart uWSGI Emperor - name: Enable app server configuration (uWSGI emperor) template: src: uwsgi....

June 5, 2022 · 4 min · Jaaved Khan

File Object in Django

Summary suspendedfc position ease box interval due front 2.50 2 1.00 2021-05-06T10:05:12Z https://docs.djangoproject.com/en/3.1/ref/files/file/ The File class is a thin wrapper around a Python file object(File Object in Python) with some Django-specific additions. Internally, Django uses this class when it needs to represent a file. code class File(file_object): pass “file_object” is the underlying File Object in Python that this class wraps....

April 4, 2022 · 2 min · Jaaved Khan

Storing Pillow Image object to Django FileField(ImageField)

Requirement Image object in Pillow to File Object in Django and save them as FileField and FieldFile Methods From Stackoverflow ref: link import StringIO from django.core.files.uploadedfile import InMemoryUploadedFile # Create a file-like object to write thumb data (thumb data previously created # using PIL, and stored in variable 'thumb') thumb_io = StringIO.StringIO() thumb.save(thumb_io, format='JPEG') # Create a new Django file-like object to be used in models as ImageField using # InMemoryUploadedFile....

April 4, 2022 · 1 min · Jaaved Khan

Date Conversion from Django Template to JavaScript

In E-invoicing(Fatoorah) project there was a requirement to use DataTables <td> object.time_stamp.isoformat </td> $.fn.dataTable.ext.search.push( function(settings, data, dataIndex) var min = minDate.val(); var max = maxDate.val(); let dateTime = data[1]; // here !!!!!!!!!!!!! var date = new Date(dateTime); if ( (min === null && max === null) || (min === null && date <= max) || (min <= date && max === null) || (min <= date && date <= max) ) return true; return false; ); From here: https://stackoverflow....

April 4, 2022 · 1 min · Jaaved Khan

Querysets

Querysets in fc position ease box interval due front 2.95 5 51.57 2021-10-21T21:35:48Z Custom querysets are configured by the model manager Calling custom queryset method from manager class PersonQuerySet(models.QuerySet): def authors(self): return self.filter(role='A') def editors(self): return self.filter(role='E') class PersonManager(models.Manager): def get_queryset(self): return PersonQuerySet(self.model, using=self._db) def authors(self): # verbose return self.get_queryset().authors() def editors(self): # verbose return self.get_queryset().editors() class Person(models.Model): first_name = models....

April 4, 2022 · 1 min · jaavedkhan

CSRF protection (in Django)

Summary The CSRF middleware and template tag provides easy-to-use protection against CSRF Forgeries. ref https://docs.djangoproject.com/en/3.2/ref/csrf/ Protection fc position ease box interval due front 2.5 0 0 2021-09-12T07:15:09Z The first defense against CSRF attacks is to ensure that GET requests (and other ‘safe’ methods, as defined by RFC 7231#section-4.2.1) are side effect free. Requests via ‘unsafe’ methods, such as POST, PUT, and DELETE, can then be protected by following the steps below....

April 4, 2022 · 7 min · Jaaved Khan

FileField and FieldFile

Summary https://docs.djangoproject.com/en/3.1/ref/models/fields/#filefield-and-fieldfile When you access a FileField on a model, you are given an instance of FieldFile as a proxy for accessing the underlying file. The API of FieldFil mirrors that of File(File Object in Django), with one key difference: The object wrapped by the class is not necessarily a wrapper around Python’s built-in file object. Instead, it is a wrapper around the result of the Storage.open() method, which may be a File object, or it may be a custom storage’s implementation of the File API....

April 4, 2022 · 3 min · Jaaved Khan