Skip to content

Instantly share code, notes, and snippets.

View Tobi-De's full-sized avatar
👁️‍🗨️
Trade-offs everywhere!

Tobi Tobi-De

👁️‍🗨️
Trade-offs everywhere!
View GitHub Profile
from datetime import datetime
"""
Called during request:
process_request(request)
process_view(request, view_func, view_args, view_kwargs)
Called during response:
process_exception(request, exception) (only if the view raised an exception)
process_template_response(request, response) (only for template responses)

Modif

  • put the script right after the first place I talk about requirements
  • precise where some command are not needed when the user is using cookiecutter, for example to avoid using pip freeze.

In this post we are going to see how you can easily deploy your awesome Django project on a linux server( Virtual Private Server a.k.a vps ). In this tutorial I will be using DigitalOcean, a well know cloud provider that offers you a full control on your server, I also choose DigitalOcean because they have a 1-click app Dokku droplet to get you up and running quickly.

What is Dokku ?

Through this guide we will see how to start a new django project using a cookiecutter, this guide is intended for beginners who already have experience with django, and who wants to know how to start a project following the best web standards. We will be using the cookiecutter-django, like it is said on the official github page, it is a framework for jumpstarting production-ready Django projects quickly.

what is cookiecutter ?

The cookiecutter project was initiated by https://github.com/audreyfeldroy, the co-author of the excellent Two Scoops of Django. It is a command-line utility that creates projects from cookiecutters (project templates). There are a multitude of cookiecutters for various frameworks, django, flask, etc ..., you can consult the list of cookiecutters avai

This is neither a guide nor a tutorial, but a list of django packages that are very well known and used in the community and which I have already used myself. I will update this list as I discover new packages. If you can't find a package in this list that matches your requirements, you can always head to the djangopackages website which has a list of most django packages. It's a bit like the official django packages website.

Packages I've tried and used inside my projects.

  • django-crispy-forms: If you are not a frontend pro like, this package will help you render your forms nicely with a little to no efforts, and it is very customisable. It comes with support for multiple frontend framework like bootstrap for example.
  • django-allauth: This package for me and many others is a must have if you need to handle users authentications and r
@Tobi-De
Tobi-De / models.py
Created December 5, 2020 12:52
Multiple Users model using Proxy models, code originated from https://github.com/pydanny/multiple-user-types-django
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
class User(AbstractUser):
class Types(models.TextChoices):
SPY = "SPY", "Spy"
DRIVER = "DRIVER", "Driver"
@Tobi-De
Tobi-De / forms.py
Created December 6, 2020 06:19
Cutomize django allauth signup form, from https://github.com/pydanny/multiple-user-types-django
from django import forms as d_forms
from allauth.account.forms import SignupForm
# SpyBookSignupForm inherits from django-allauth's SignupForm
class SpyBookSignupForm(SignupForm):
# Specify a choice field that matches the choice field on our user model
type = d_forms.ChoiceField(choices=[("SPY", "Spy"), ("DRIVER", "Driver")])
# Override the init method
@Tobi-De
Tobi-De / sheet.md
Last active March 20, 2021 06:46
Typescript cheat sheet
@Tobi-De
Tobi-De / htmx.md
Last active March 27, 2025 20:15
Simple django CBV using django-htmx

Django-htmx guide setup

Simple guide to setup django-htmx in a django project. In this guide we assume that you already have a django project setup in a virtualenv and you only wish to add django-htmx to your project.

  1. Install the django-htmx package

     pip install django-htmx
    
  2. Add django-htmx to your INSTALLED_APPS:

@Tobi-De
Tobi-De / base.html
Last active July 6, 2023 10:48
soft ui dashboard django
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{% block title %}izimanage{% endblock title %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="accountancy software">
<meta name="author" content="Tobi DEGNON">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
@Tobi-De
Tobi-De / utils.py
Last active July 6, 2023 11:07
Some django utils I usually have in my projects
# render pdf using weasyprint
# depends on: weasyprint
import weasyprint
from django.template.loader import render_to_string
def render_to_pdf(template_src, context_dict=None):
html = render_to_string(template_src, context_dict)
try:
pdf = weasyprint.HTML(string=html).write_pdf()
except Exception as e: