Skip to content

Instantly share code, notes, and snippets.

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = 'var/static_root/'
STATICFILES_DIRS = ['static']
const path = require('path');
module.exports = {
publicPath: '/static/src/vue/dist/', // Should be STATIC_URL + path/to/build
outputDir: path.resolve(__dirname, '../static/src/vue/dist/'), // Output to a directory in STATICFILES_DIRS
filenameHashing: false, // Django will hash file names, not webpack
runtimeCompiler: true, // See: https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
devServer: {
writeToDisk: true, // Write files to disk in dev mode, so Django can serve the assets
},
{% load static %}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Testing Vue...</h1>
<div id="app"></div>
alias foo="echo 'I pity the foo'"
@bennett39
bennett39 / test_my_command.py
Created September 27, 2021 10:54
Testing Django Admin Commands
from io import StringIO
from django.core.management import call_command
from django.test import TestCase
class MyCommandTest(TestCase):
def test_my_command(self):
out = StringIO() # <-- Use StringIO to capture the output of the command from stdout
args = [] # <-- Any command line arguments go here
kwargs = {'stdout': out} # <-- Any named command line options (e.g. --my-option) go here
# Map, filter, and reduce are all operations that we can apply against a list, tuple, or sequence
# These types of operations follow the "functional" approach to programming
# I won't go into too much detail here, but a Google search of "functional vs OOP" will give you a synopsis
# Here are some examples. We can talk more about them when we chat.
# Let's start with a simple list...
>>> my_list = [0, 1, 2, 3, 4, 5]
# Using filter, we can filter values out of the list, returning a new list!
# (If you haven't seen lambdas yet, don't worry! Basically, this filter uses modulo 2 to check if the number is even/odd)
def fib(n):
"""Calculate the Nth fibonacci number.
Intentionally don't use dynamic programming. Goal is to simulate a long-running task.
"""
if n < 0:
raise ValueError('Negative numbers are not supported')
elif n == 0:
return 0
elif n <= 2:
from django.db import models
class Calculation(models.Model):
"""Track a calculation and its results"""
EQUATION_FIBONACCI = 'FIB'
EQUATIONS = ((EQUATION_FIBONACCI, 'Fibonacci'),)
STATUS_PENDING = 'PENDING'
STATUS_ERROR = 'ERROR'
from django.shortcuts import render, redirect
from django.views import View
from .models import Calculation
from .tasks import fibonacci_task
class FibonacciView(View):
def get(self, request):
"""Show a form to start a calculation"""
from celery_tutorial.celery import app
from .models import Calculation
def fib(n):
"""Calculate the Nth fibonacci number"""
if n < 0:
raise ValueError('Negative numbers are not supported')
elif n == 0:
return 0