go mod init
: start new module, this will put a "go.mod" file in the current directory
go get <package>
: install dependency
go run <module_name>
: Run
go build <module_name>
: compile executable
CREATE EXTENSION ltree; | |
CREATE TABLE test (path ltree); | |
-- Top | |
-- / | \ | |
-- Science Hobbies Collections | |
-- / | \ | |
-- Astronomy Amateurs_Astronomy Pictures |
In Django REST Framework views (this includes anything that might be called from a view), anytime when an exception occurs it will get handled by the framework.
To provide more customized error response with the appropriate status code, you will want to raise a subclass of APIException:
from rest_framework.exceptions import ValidationError
CSP limits our site from making requests to other sites, controls what resources the page is allowed to load. It limits the damage even if malicious code is running in a user's browser within our site's context.
Content-Security-Policy: default-src ‘self’
Prevents loading resources from other domains. Prevents inline scripts, such as <script>alert('hello')</script>
.
Content-Security-Policy: default-src ‘self’ *.trusted.com
Cookie sent over unencrypted HTTP connection
Use Secure
attribute on cookie to prevent it from being sent over unencrypted connection: Set-Cookie: key=value; Secure
There are two typical models for dealing with tree data structure in SQL databases: adjacency list model and nested set model. There are several packages for Django that implements these models such as django-mptt, django-tree-queries, and django-treebeard.
In this article, I want to explain a different approach I took in a project for storing hierachichal data, as well as search and retrieval of sub-trees. This approach is similar in principle to materialzed path, which django-treebeard package also provides an implementation. This article will show you how I achieved this without any of the specific packages, and using on
This article is based on my Stackoverflow answer - Django query lookup 'startswith' on table fields.
Let's say you have a table of partial postal codes:
| codes |
----------
| A1A |