<jupyter_start><jupyter_text>Create an Example Django Project  Use django-admin to bootstrap the project<jupyter_code># dont_test

%cd ..
# dont_test

!django-admin startproject example<jupyter_output>[0m<jupyter_text>Views<jupyter_code>%%writefile example/example/views.py
# dont_test

import aiofiles

from pathlib import Path

from django.conf import settings
from django.http import HttpResponse
from django.http import FileResponse

from fileresponse.http import AiofileFileResponse
from fileresponse.http import AiobotocoreFileResponse


def get_file(request, num=None):
    file_path = Path(__file__).parent.parent / "data" / str(num)
    print(str(file_path))
    return FileResponse(file_path.open("rb"))


async def aget_file(request, num=None):
    file_path = Path(__file__).parent.parent / "data" / str(num)
    return AiofileFileResponse(file_path, chunk_size=4096)


async def aminio_get_file(request, num=None):
    bucket = settings.DJANGO_AWS_STORAGE_BUCKET_NAME
    key = str(num)
    return AiobotocoreFileResponse(bucket, key, chunk_size=4096)<jupyter_output>Overwriting example/example/views.py<jupyter_text>Urls<jupyter_code>%%writefile example/example/urls.py
# dont_test

from django.urls import path

from . import views

urlpatterns = [
    path("sync/<int:num>", views.get_file),
    path("async_filesystem/<int:num>", views.aget_file),
    path("async_minio/<int:num>", views.aminio_get_file),
]<jupyter_output>Overwriting example/example/urls.py<jupyter_text>ASGI<jupyter_code>%%writefile example/example/asgi.py
# dont_test
import os
import django

from fileresponse.asgi import get_asgi_application

from . import urls

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'example.settings')
application = get_asgi_application()<jupyter_output>Overwriting example/example/asgi.py<jupyter_text>Settings<jupyter_code>%%writefile example/example/settings.py
# dont_test


from pathlib import Path

# Build paths inside the project like this: BASE_DIR / "subdir".
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-eyj(*+5=#xb1(5$50p*k0%5evl)80dcoh(i6(tx9a7dq9i5#9f"

# SECURITY WARNING: don"t run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
]

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "example.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
            ],
        },
    },
]

WSGI_APPLICATION = "example.wsgi.application"


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = "/static/"

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# AWS S3 / MinIO settings
FILERESPONSE_S3_ACCESS_KEY_ID="minioadmin"
FILERESPONSE_S3_SECRET_ACCESS_KEY="minioadmin"
FILERESPONSE_S3_REGION="us-west-2"
FILERESPONSE_S3_STORAGE_BUCKET_NAME="fileresponse"
FILERESPONSE_S3_ENDPOINT_URL="http://localhost:9000"<jupyter_output>Overwriting example/example/settings.py<jupyter_text>Apply Migrations<jupyter_code># dont_test

%cd example
!python manage.py migrate<jupyter_output>/Users/jochen/projects/django_fileresponse/example
[36;1mOperations to perform:[0m
[1m  Apply all migrations: [0madmin, auth, contenttypes, sessions
[36;1mRunning migrations:[0m
  Applying contenttypes.0001_initial...[32;1m OK[0m
  Applying auth.0001_initial...[32;1m OK[0m
  Applying admin.0001_initial...[32;1m OK[0m
  Applying admin.0002_logentry_remove_auto_add...[32;1m OK[0m
  Applying admin.0003_logentry_add_action_flag_choices...[32;1m OK[0m
  Applying contenttypes.0002_remove_content_type_name...[32;1m OK[0m
  Applying auth.0002_alter_permission_name_max_length...[32;1m OK[0m
  Applying auth.0003_alter_user_email_max_length...[32;1m OK[0m
  Applying auth.0004_alter_user_username_opts...[32;1m OK[0m
  Applying auth.0005_alter_user_last_login_null...[32;1m OK[0m
  Applying auth.0006_require_contenttypes_0002...[32;1m OK[0m
  Applying auth.0007_alter_validators_add_error_messages...[32;1m OK[0m
  Applying auth.0008_alter_user_username_max_length...[32;[...]<jupyter_text>Link example to Notebooks Directory<jupyter_code># dont_test

%cd ../nbs
!ln -s ../example/example .
%cd -<jupyter_output>/Users/jochen/projects/django_fileresponse/nbs
ln: ./example: File exists
/Users/jochen/projects/django_fileresponse/example<jupyter_text>Start ServerJust run:```shellpython manage.py runserver 0.0.0.0:8000```<jupyter_code># dont_test

!python manage.py runserver 0.0.0.0:8000<jupyter_output>Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
June 21, 2021 - 08:13:00
Django version 3.2.3, using settings 'example.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
/Users/jochen/projects/django_fileresponse/example/data/0
[21/Jun/2021 08:13:25] [m"GET /0 HTTP/1.1" 200 10485760[0m
/Users/jochen/projects/django_fileresponse/example/data/1
[21/Jun/2021 08:13:25] [m"GET /1 HTTP/1.1" 200 10485760[0m
/Users/jochen/projects/django_fileresponse/example/data/2
[21/Jun/2021 08:13:25] [m"GET /2 HTTP/1.1" 200 10485760[0m
/Users/jochen/projects/django_fileresponse/example/data/3
[21/Jun/2021 08:13:25] [m"GET /3 HTTP/1.1" 200 10485760[0m
/Users/jochen/projects/django_fileresponse/example/data/4
[21/Jun/2021 08:13:25] [m"GET /4 HTTP/1.1" 200 10485760[0m
/Users/jochen/projects/django_fileresponse/example/data/5
[21/Jun/2021 08:13:25] [m"GET /5 HTTP/1.1" 200 10485760[0m
[...]
{'fraction_non_alphanumeric': 0.12873862158647595, 'fraction_numerical': 0.04928478543563069, 'mean_word_length': 4.826515151515151, 'pattern_counts': {'":': 12, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '547719', 'license': 'Apache-2.0', 'n_tokens_mistral': 3052, 'n_tokens_neox': 2754, 'n_words': 424, 'path': 'nbs/create_sample_django_project.ipynb', 'repo_name': 'ephes/django-fileresponse', 'size': '7690'}