Django packages that I use in my projects

django best packages

Using packages makes your work easier and makes the development of a project much faster. In this article I present the packages that I find useful and that I use in my projects.

These packages that will simplify your life with Django. I invite you to share in comments your favorite Django packages that you use and why.

Pillow

Any time you work with ImageFields you have to install an image library, e.g Pillow. Pillow is the “friendly” PIL, while PIL is the Python Imaging.

How to install Pillow?

PIL and Pillow currently cannot co-exist in the same environment. If you want to use Pillow, you have to remove PIL first.
You can install Pillow with pip:

pip install Pillow

Django Cleanup

in Django unfortunately, after deleting an image it remains stored in the media directory.
If in your project you work a lot with images, files, in time the space occupied on the disk increases, which is an inconvenience.

You can modify to physically delete the files from the code or use Django Cleanup package.

First, install django cleanup package:

pip install django-cleanup

Then, add django_cleanup app in your settings.py INSTALLED_APPS:


INSTALLED_APPS = (
    ...
    'django_cleanup', # should go after your apps

)

The django-cleanup app automatically deletes files for FileField, ImageField and subclasses.
When a FileField’s value is changed and the model is saved, the old file is deleted. When a model that has a FileField is deleted, the file is also deleted.

psycopg2 – Python-PostgreSQL Database Adapter

Psycopg2 is the most popular PostgreSQL database adapter for the Python programming language.

How to install psycopg2?

pip install psycopg2

psycopg2-binary

You can also obtain a stand-alone package, not requiring a compiler or external libraries, by installing the psycopg2-binary package from PyPI:

pip install psycopg2-binary

The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources.

pip install psycopg2-binary

!!When I deployed a Django app on shared hosting with a postreSQL database, I could not install psycopg2, but I worked with psycopg2-binary.

Using font-awesome in Python Django application

django-fontawesome is a Django app that provides a couple of Fontawesome related utilities, namely:
– an IconField to associate Fontawesome icons with model instances
– templatetags to render Fontawesome icons

1. Install django-static-fontawesome library

pip install django-fontawesome

2. Add ‘fontawesome’ to your installed apps setting

INSTALLED_APPS = (

‘fontawesome’,
)

django-file-resubmit

In Django project you have forms with FileField, ImageField. Everything works great, but when ValidationError is raised, you have to reselect all files and images again. It is kind of annoying. django-file-resubmit solves this problem. It works with FileField, ImageField and sorl.thumbnail.ImageField.

How Django file resubmit work?

Here are special widgets for FileField and ImageField. When you submit files, every widget saves its file in cache. And when ValidationError is raised, widgets restore files from cache. Read more here about Django file resubmit

How to install Django resubmit?

pip install django-file-resubmit

Creating Sitemaps in Django.

XML Sitemap is the most preferred way of creating sitemaps. Django provides django.contrib.sitemaps a sitemap framework, which automates the process of creating sitemaps.

Use django.contrib.sitemaps to create sitemap for Your site

Read here about How to create a sitemap in Django.

Django Simple Cookie Consent notice

I tested the packages below for cookie consent:

Django cookie consent

Django cookie consent is a reusable application for managing various cookies and visitors consent for their use in Django project. Provides support for both opt-in and opt-out cookie consent schemes.

Cookies and cookie groups are stored in models for easy management through Django admin interface.

Django cookie law

Django cookie law will display a dismissable banner, making your users aware of cookies being used.

Django Simple Cookie Consent

Django Simple Cookie Consent is a simple Django app to display a custom cookie message. By far, it was the easiest to set up and I used it in my Django applications.
Each visitor to the site will get a popup to say that the site uses cookies.

How to install Django Simple Cookie Consent?

1. pip install django-simple-cookie-consent

2. Add “django_simple_cookie_consent” to your INSTALLED_APPS setting

3. Add “{% load django_simple_cookie_consent_tags %}” to your base template then place “{% display_cookie_consent %}” somewhere in the head tag like this:
…other loads
{% load django_simple_cookie_consent_tags %}

…other links/scripts
{% display_cookie_consent %}

4. Run ‘python manage.py migrate’ to create the CookieConsentSettings model.

5. Visit admin panel and create a settings instance (you’ll need the Admin app enabled)

Django admin honeypot

django-admin-honeypot is a fake Django admin login screen to log and notify admins of attempted unauthorized access. This app was inspired by discussion in and around Paul McMillan’s security talk at DjangoCon 2011.

How to install Django admin honeypot?

1. Install django-admin-honeypot from PyPI:

pip install django-admin-honeypot

2. Add admin_honeypot to INSTALLED_APPS

3. Update your urls.py:

    urlpatterns = patterns(''
    path('admin/', include('admin_honeypot.urls', namespace='admin_honeypot')),
    path('secret/', admin.site.urls),   
    )

4. Run python manage.py migrate

Hello there!

I hope you find this post useful!

I'm Mihai, a programmer and online marketing specialist, very passionate about everything that means online marketing, focused on eCommerce.

If you have a collaboration proposal or need helps with your projects feel free to contact me. I will always be glad to help you!

subscribe youtube

Leave a Reply

Your email address will not be published. Required fields are marked *