PageView

Stories about Python, Django and Web Development

How to Setup Amazon S3 in a Django Project

How to Setup Amazon S3 in a Django Project

In this tutorial you will learn how to use the Amazon S3 service to handle static assets and the user uploaded files, that is, the media assets.

Read more



Ask Vitor #3: Mocking Emails

Ask Vitor #3: Mocking Emails

Phillip Ahereza asks:

I’m writing unit tests for my django app and I was wondering if there are any packages for mocking email or if there is any way I could mock sending and receiving of emails.

Read more



Django Tips #20 Working With Multiple Settings Modules

Django Tips #20 Working With Multiple Settings Modules

Usually, it’s a good idea to avoid multiple configuration files, instead, keep your project setup simple. But that’s not always possible, as a Django project starts to grow, the settings.py module can get fairly complex. In those cases, you also want to avoid using if statements like if not DEBUG: # do something.... For clarity and strict separation of what is development configuration and what is production configuration, you can break down the settings.py module into multiple files.

Read more



How to Configure Mailgun To Send Emails in a Django Project

How to Configure Mailgun To Send Emails in a Django Project

In this tutorial you will learn how to setup a Django project to send emails using the Mailgun service.

Read more



How to Deploy a Django Application on RHEL 7

How to Deploy a Django Application on RHEL 7

In this tutorial, you will learn how to deploy a Django application with PostgreSQL, Nginx, Gunicorn on a Red Hat Enterprise Linux (RHEL) version 7.3. For testing purpose I’m using an Amazon EC2 instance running RHEL 7.3.

Read more



Ask Vitor #2: How to dynamically filter ModelChoice's queryset in a ModelForm?

Ask Vitor #2: How to dynamically filter ModelChoice's queryset in a ModelForm?

Michał Strumecki asks:

I just want to filter select field in a form, regarding a currently logged user. Every user has own categories and budgets. I want to display only a models related with a currently logged user. I’ve tried stuff with filtering before is_valid field, but with no result.

Read more



Class-Based Views vs. Function-Based Views

Class-Based Views vs. Function-Based Views

If you follow my content here in the blog, you probably have already noticed that I’m a big fan of function-based views. Quite often I use them in my examples. I get asked a lot why I don’t use class-based views more frequently. So I thought about sharing my thoughts about that subject matter.

Read more



Ask Vitor #1: Getting form data to appear in URL and for use in the next view

Ask Vitor #1: Getting form data to appear in URL and for use in the next view

Devon Moore asks:

I want to have the user specify a date in a custom form. This date will append the current URL with the date value path/YYYY-MM-DD/ I then need to capture the date and use it to filter data from the database to display that date’s data.
I’m using class based views and for the report I’m using generic view since this view is a custom report I’m building using multiple db models.

Read more



How to Create Django Admin List Actions

How to Create Django Admin List Actions

Django Admin list actions are meant to be used to perform operations in bulk. All Django Admin list views already come with a default action “Delete selected <ModelName>s”. In this short tutorial I will guide you through the steps to create your own list actions.

Read more



How to Create Infinite Scroll With Django

How to Create Infinite Scroll With Django

In this tutorial I will show you how to implement a very simple infinite scrolling with Django. Basically we will take advantage of Django’s pagination API and a jQuery plug-in. You will find examples using both function-based views and class-based views.

Read more