From e0512a5e9609365c54852733e76d1a772e2727c5 Mon Sep 17 00:00:00 2001 From: Denis Bobrov Date: Sat, 23 Oct 2021 22:51:36 +0300 Subject: [PATCH 1/3] Added django minimal example --- examples/django-minimal/.gitignore | 1 + examples/django-minimal/DjangoMinimal.fsproj | 15 ++++++ examples/django-minimal/Program.fs | 48 ++++++++++++++++++++ examples/django-minimal/README.md | 32 +++++++++++++ examples/django-minimal/requirements.txt | 1 + 5 files changed, 97 insertions(+) create mode 100644 examples/django-minimal/.gitignore create mode 100644 examples/django-minimal/DjangoMinimal.fsproj create mode 100644 examples/django-minimal/Program.fs create mode 100644 examples/django-minimal/README.md create mode 100644 examples/django-minimal/requirements.txt diff --git a/examples/django-minimal/.gitignore b/examples/django-minimal/.gitignore new file mode 100644 index 0000000..8e5bbf0 --- /dev/null +++ b/examples/django-minimal/.gitignore @@ -0,0 +1 @@ +*.py \ No newline at end of file diff --git a/examples/django-minimal/DjangoMinimal.fsproj b/examples/django-minimal/DjangoMinimal.fsproj new file mode 100644 index 0000000..c3f22c9 --- /dev/null +++ b/examples/django-minimal/DjangoMinimal.fsproj @@ -0,0 +1,15 @@ + + + + Exe + net5.0 + 3390;$(WarnOn) + + + + + + + + + \ No newline at end of file diff --git a/examples/django-minimal/Program.fs b/examples/django-minimal/Program.fs new file mode 100644 index 0000000..c8363ff --- /dev/null +++ b/examples/django-minimal/Program.fs @@ -0,0 +1,48 @@ +// Learn more about F# at http://docs.microsoft.com/dotnet/fsharp +module Program + +open System +open System.Collections.Generic +open Fable.Core +open Fable.Python +open Fable.Core.PyInterop + +type ISettings = + [] + abstract configure : DEBUG: bool * ROOT_URLCONF : obj -> unit + + +[] +let settings: ISettings = nativeOnly +type IPath = + abstract path : url: string * view: obj -> obj + +[] +let urls: IPath = nativeOnly + + +[] +let HttpResponse: string -> obj = nativeOnly + + +[] +let execute_from_command_line: string [] -> int = nativeOnly + +[] +let sysModules : unit -> obj = nativeOnly + +settings.configure ( + DEBUG=true, + ROOT_URLCONF = sysModules +) + +let index request = + HttpResponse("

A minimal Django response!

") + +let urlpatterns = [| + urls.path ("",index) +|] + +[] +let main argv = + execute_from_command_line (argv) diff --git a/examples/django-minimal/README.md b/examples/django-minimal/README.md new file mode 100644 index 0000000..ea7f85f --- /dev/null +++ b/examples/django-minimal/README.md @@ -0,0 +1,32 @@ +# Fable Python on Django + +A minimal example (single file). + +## Credits + +https://github.com/rnevius/minimal-django + +## Install Dependencies + +```sh +> dotnet tool restore +> dotnet restore + +> pip install -r Django +``` + +## Build + +``` +> dotnet fable-py +``` + +## Run + +Note that the first argument is skipped, because of `main(sys.argv[1:])` for some reason +```sh +> python3 program.py skipped runserver +``` + +Visit http://127.0.0.1:8000/ + diff --git a/examples/django-minimal/requirements.txt b/examples/django-minimal/requirements.txt new file mode 100644 index 0000000..699ce5c --- /dev/null +++ b/examples/django-minimal/requirements.txt @@ -0,0 +1 @@ +Django>=3.2.8,<4.0.0 \ No newline at end of file From 0b0fd4c76d61bb15aa2484919500f035a529b93b Mon Sep 17 00:00:00 2001 From: Denis Bobrov Date: Sat, 23 Oct 2021 22:59:30 +0300 Subject: [PATCH 2/3] Fix using sys.argv --- examples/django-minimal/Program.fs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/django-minimal/Program.fs b/examples/django-minimal/Program.fs index c8363ff..beee64b 100644 --- a/examples/django-minimal/Program.fs +++ b/examples/django-minimal/Program.fs @@ -28,6 +28,9 @@ let HttpResponse: string -> obj = nativeOnly [] let execute_from_command_line: string [] -> int = nativeOnly +[] +let sys : obj = nativeOnly + [] let sysModules : unit -> obj = nativeOnly @@ -45,4 +48,4 @@ let urlpatterns = [| [] let main argv = - execute_from_command_line (argv) + execute_from_command_line (sys?argv) From 7b12ae08f1f0ad1ffb03a75f9f6b6ad81361369f Mon Sep 17 00:00:00 2001 From: Denis Bobrov Date: Sat, 23 Oct 2021 23:05:34 +0300 Subject: [PATCH 3/3] Fix readme --- examples/django-minimal/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/django-minimal/README.md b/examples/django-minimal/README.md index ea7f85f..8f65d59 100644 --- a/examples/django-minimal/README.md +++ b/examples/django-minimal/README.md @@ -12,7 +12,7 @@ https://github.com/rnevius/minimal-django > dotnet tool restore > dotnet restore -> pip install -r Django +> pip3 install -r requirements.txt ``` ## Build @@ -23,9 +23,8 @@ https://github.com/rnevius/minimal-django ## Run -Note that the first argument is skipped, because of `main(sys.argv[1:])` for some reason ```sh -> python3 program.py skipped runserver +> python3 program.py runserver ``` Visit http://127.0.0.1:8000/