Skip to content

Instantly share code, notes, and snippets.

@bradtraversy
bradtraversy / django_deploy.md
Last active April 4, 2024 11:28
Django Deployment - Digital Ocean

Django Deployment to Ubuntu 18.04

In this guide I will go through all the steps to create a VPS, secure it and deploy a Django application. This is a summarized document from this digital ocean doc

Any commands with "$" at the beginning run on your local machine and any "#" run when logged into the server

Create A Digital Ocean Droplet

Use this link and get $10 free. Just select the $5 plan unless this a production app.

@c00kiemon5ter
c00kiemon5ter / create-superuser.py
Created June 16, 2017 11:31
Extend Django's management createsuperuser command to allow non-interactive creation of a superuser with a password.
"""
Extend createsuperuser command to allow non-interactive creation of a
superuser with a password.
Instructions:
mkdir -p path-to-your-app/management/commands/
touch path-to-your-app/management/__init__.py
touch path-to-your-app/management/commands/__init__.py
@clungzta
clungzta / transparent_overlay_cv2.py
Created March 28, 2017 10:20
Example for overlaying a transparent image onto a background image using cv2
import numpy as np
import cv2
img = cv2.imread('background.jpg')
overlay_t = cv2.imread('foreground_transparent.png',-1) # -1 loads with transparency
def overlay_transparent(background_img, img_to_overlay_t, x, y, overlay_size=None):
"""
@brief Overlays a transparant PNG onto another image using CV2
@leofaster
leofaster / Django DB hits Count
Last active June 30, 2021 08:39
Count the numbers of hits to database
from django.db import connection
print(len(connection.queries))
from django.db import reset_queries
reset_queries()
@flaugher
flaugher / gist:ec36ec940a31707ac683
Created March 1, 2015 20:03
Things to do if your Django form.is_valid() method fails
- Check that you inserted "request.POST" as an argument to your form when instantiating the form in your view after the POST.
- Add {{ form.errors }} {{ form.non_field_errors }} to the form or debug your view and print them from the debugger.
- Examine each form field in the debugger: myform['<fieldname>'].value()
- Make sure DEBUG = True so that you'll see any server errors.
- Check your server log.
- If all else fails, step through the is_valid() call.
@douglasmiranda
douglasmiranda / gist:5408278
Created April 17, 2013 22:26
Leading zeros in django templates
{{ variable|stringformat:"02d" }}
@toshism
toshism / gist:1571984
Created January 6, 2012 19:20
django split datetime fields
#models.py
class Activity(models.Model):
name = models.CharField()
start = models.DateTimeField()
end = models.DateTimeField()
#forms.py
@thanksmister
thanksmister / TimeZoneUtil.as
Created October 6, 2011 22:19
Utility class for determining local machine timezone in Flex, AIR, and AS3.
package
{
public class TimeZoneUtil
{
import com.adobe.utils.DateUtil;
/**
* List of timezone abbreviations and matching GMT times.
* Modified form original code at:
* http://blog.flexexamples.com/2009/07/27/parsing-dates-with-timezones-in-flex/