Django Crawfish
Overview
Installation
Using pip:
$ pip install django-crawfish
Basic Usage
Add crawfish to INSTALLED_APPS in your settings. Crawfish does not require installation in any particular order.
INSTALLED_APPS = [
# Other apps
"crawfish"
]
Models
Crawfish includes base models and fields for better Django models.
Models
from crawfish.models import BaseModel
Fields
from crawfish.models import EmailField
Middleware
Crawfish includes base models and fields for better Django models.
ErrorPagesMiddleware
Automatically override response body when requests are made using header Content-Type: application/json that generates a response with status code 403, 404, or 500 response.
Add to your middleware list either last or as late as possible. This is to ensure this middleware is run early in the response cycle to avoid supressing any other middleware int the request cycle.
More information available in the Django documentation.
MIDDLEWARE = [
# other middleware
"crawfish.middleware.ErrorPagesMiddleware
]
Future Plans
Configure static or dynamic response body content in settings.
Decorator to enable/disable middleware on individual views.
Mixins
Crawfish includes base models and fields for better Django models.
ApiErrorsMixin
from crawfish.mixins import ApiErrorsMixin
usage:
class MyModel(ApiErrorsMixin, models.Model):
...
ApiErrorsMixin adds the following attributes to the model:
errors
: a list of errors
error_messages
: a dictionary of error messages
WIP: This ^^ was generated entirely with GitHub Copilot. Come back soon for proper documentation.
DataclassMappingMixin
from crawfish.mixins import DataclassMappingMixin
usage:
@dataclass
class MyModel(DataclassMappingMixin):
field1: str
field2: str
...
WIP
Crawfish API
Test